-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
XState version
XState version 5
Description
When defining the "on" property at the top-level:
{
id: "parallelExample",
type: "parallel",
on: {
INQUIRY: {
target: "#parallelExample.phase.inquiry",
},
ARCHIVE: {
target: "#parallelExample.phase.archive",
},
EDIT: {
target: "#parallelExample.mode.edit",
},
NEW: {
target: "#parallelExample.mode.new",
},
},
states: {
phase: {
initial: "inquiry",
states: {
inquiry: {
entry: {
type: "phase.inq",
},
},
archive: {
entry: {
type: "phase.archive",
},
},
},
},
mode: {
initial: "new",
states: {
new: {
entry: {
type: "mode.new",
},
},
edit: {
entry: {
type: "mode.edit",
},
},
},
},
},
}
After the non-initial state was set (for example when mode = edit), by default it's "new". When triggering the following
{ type: "ARCHIVED" }
It transitions phase => archived (GOOD), and transitions mode => new (BAD), likely due to mode's initial state being "new".
Expected result
I'd expect only the phase to transition the state, not the mode. When you look at the stately visualizer, it visualizes how I expected it as well: https://stately.ai/registry/editor/a7786eef-4feb-4e0a-8a80-57b27fb7125b?mode=Simulate&machineId=183393aa-804a-4cdc-8c5d-a6fc9a462ee3
- Click on Edit => goes to Edit
- Click on Archived => Edit stays in edit, inquiry becomes archived
Actual result
However, in reality, if you open up the stackblitz, you will notice that transitioning from a
- phase: inquiry
- mode: edit
by pressing ARCHIVE, it will transition to:
- phase: archived
- mode: new
And this is also the bug we encountered in our codebase.
Reproduction
Additional context
Notice that the behavior of the stackblitz and stately visualizer is different. So, what I'm suspecting is either a bug in xstate, since the visualizer indicates what I'd expect, while stackblitz doesn't. A misunderstanding on my part, but then stately visualizer output is confusing if the stackblitz version is intended behavior.
Perhaps related to this doc? https://stately.ai/registry/editor/c1ea71b5-dc16-4f52-965d-9eab8f952f83