xstate-viz icon indicating copy to clipboard operation
xstate-viz copied to clipboard

Bug: onDone appears in state.nextEvents even if compound node is not in final state

Open eponymous301 opened this issue 2 years ago • 2 comments

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)

Screen Shot 2023-02-25 at 3 02 19 PM

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

eponymous301 avatar Feb 25 '23 23:02 eponymous301

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"

eponymous301 avatar Feb 25 '23 23:02 eponymous301

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.

davidkpiano avatar Mar 01 '23 10:03 davidkpiano