statelyai / xstate

Actor-based state management & orchestration for complex app logic.
https://stately.ai/docs
MIT License
26.56k stars 1.22k forks source link

Bug: #4866

Closed acrobid closed 2 months ago

acrobid commented 2 months ago

XState version

XState version 5

Description

In a parallel parent state, if a child state sends an event to a sibling, the behavior in the visual editor does not match the behavior of the actual machine.

Child A is "On" and child "B" is "Off", and event turns event "B" "On", and then an after event turns "A" "Off".

(Also, is there a better way for a single event to affect 2 parallel states.

Expected result

In the editor, the final state is:

A: Off B: On

Actual result

In Stackblitz:

A: Off B: Off

Reproduction

https://stately.ai/registry/editor/aaf32c01-ba6d-4ef2-8b99-2c41e835826f?machineId=d06b5a5d-6597-4154-8d6c-e3cd6198bef0&mode=Simulate

Additional context

XState 5 Stackblitz: https://stackblitz.com/edit/w2u9xw?file=machine.ts

davidkpiano commented 2 months ago

Better workaround: it's preferable to raise events instead:

after: {
  '500': {
    actions: raise({ type: 'Disconnect' }),
  },
},

https://stackblitz.com/edit/w2u9xw-yuhzvv?file=machine.ts

acrobid commented 2 months ago

Thank you! That solves it.

Should I close the issue? Is the disconnect between the editor and actual behavior simply due to me using it improperly?

davidkpiano commented 2 months ago

Thank you! That solves it.

Should I close the issue? Is the disconnect between the editor and actual behavior simply due to me using it improperly?

Not your fault; the editor may be slightly misleading regarding this.