Dynamically Generated State Objects Not Recognized by XState #5232
Unanswered
oeooo12312
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Issue: Dynamically Generated State Objects Not Recognized by XState
Description
XState fails to correctly interpret state objects generated by a function, even when they are deeply equal to objects defined directly within the
states
configuration. This results in the state machine not transitioning as expected.Reproduction
Expected Behavior
The state machine should transition from one to two when the NEXT event is sent. The console.log statement should output:
Actual Behavior
Undefined , state 'one' not found.
Requirements
Additional Context
isEqual from lodash confirms that the dynamically generated object is deeply equal to a directly defined object.
The issue persists even in a minimal reproducible example, suggesting it's not related to complex state machine configurations.
This problem occurs when using machine.transition programmatically, and not only when using the XState visualizer.
Possible Causes
XState might be performing a strict reference check (using ===) on the state object, rather than just a deep equality check.
Internal metadata added by XState during parsing might be missing from dynamically generated objects.
There could be subtle differences in object properties or prototypes that are not detected by isEqual.
Thank you for your time and assistance in resolving this issue!
Beta Was this translation helpful? Give feedback.
All reactions