Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: History state in parallel machines is changing states unexpectedly #4900

Closed
ccapndave opened this issue May 17, 2024 · 3 comments
Closed

Comments

@ccapndave
Copy link

XState version

XState version 5

Description

image

Given the above machine, send the following sequence of events in the simulator:

  1. child1.next
  2. child2.next
  3. child1.history
  4. child1.history
  5. child1.history
    ...

Expected result

Whenever history is called, both machines stay in their previous state as (I think?) is expected. I use this pattern in my application to intercept events that need to do actions without changing any states.

Actual result

Although we get this result in the simulator, in real XState code it behaves differently. If both machines are in their Next states and child1.history is sent, one of the machines changes back to its initial state.

This can be reproduced by clicking on the buttons in the codesandbox. In this case when both machines are in Next and child1.history is sent, Child1 goes back to its initial state.

Reproduction

https://codesandbox.io/p/sandbox/jolly-meadow-5sxz66

Additional context

Note that in my actual app in fact it is Child2 (i.e. the machine without the history state) which goes back to its initial state and Child1 stays where it is.

@ccapndave ccapndave added the bug label May 17, 2024
@davidkpiano
Copy link
Member

It says "Sandbox not found" - can you please make it available?

@ccapndave
Copy link
Author

Sorry! Have a go now.

@davidkpiano
Copy link
Member

Workaround (as discussed on Discord):

  • Don't use a history state
  • Remove the target from the transition (make a targetless transition)
  • Only use actions: ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants