xstate-viz
xstate-viz copied to clipboard
Bug: onDone appears in state.nextEvents even if compound node is not in final state
Description
Given machine in initial state (see image), state.nextEvents includes an entry for the onDone transition. (And transition can be fired by clicking on onDone in the inspector)
Expected result
state.nextEvents == [ "start" ]- onDone transition is disabled in inspector
Actual result
state.nextEvents == [ "done.state.test.First State", "start" ]- onDone transition is enabled in inspector
- clicking causes "Second State" to become the current state.
Reproduction
https://stately.ai/viz/dafd285c-17f4-429e-b16c-9b58d0e96222
Additional context
Local env is below, but viz URL for "Reproduction" above also shows onDone enabled and clickable (although State.nextEvents is not exposed in UI so I can't verify that it also includes an entry for it)
OS X 10.15.7 node v18.12.1 [email protected] [email protected] @xstate/[email protected] @xstate/[email protected]
[email protected] running locally
NOTE: using 'Simulate' in Stately Studio at stately.ai/registry/new shows expected behavior (onDone not enabled until "First State" is in final child state "new state 2"
This is currently expected behavior for .nextEvents, since it is only responsible for showing the events that are part of the active state nodes in the state; not for whether or not an event will cause a transition.
For that, state.can(...) should be used.
But thanks for pointing this out in the XState Viz repo; moving it there.