You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think we've discovered unexpected behaviour when restoring from a persisted snapshot that has been serialized and the machine's historyValue not being restored correctly.
Take the following sample checkout machine (link to stately):
Say we go through the following path:
simulated.demo.mov
So far this looks good. The History node successfully remembers the previous "OrderSummary" state by returning to "OrderSummary.Ready" the second time around.
The problem appears to only happen if we persist the state of the machine, serialize it, and restore it.
If you run it with npm run test you'll see that the snapshots for the original actor and the restored actor do not match:
The first log is the snapshot from the original actor and the historyValue is an instance of StateNode. The second log is a snapshot of a second actor that restored the serialized state of the first actor and the historyValue is a pojo - I'm thinking this may have something to do with the bug.
So what actually happens when the second actor tries to go back to the OrderSummary history node?
Instead of returning to "OrderSummary.Ready" which the historyValue points to, the machine goes all the way to the initial state "ShippingAddress" - this is where the assertion at the end of the file fails.
Interestingly enough if we skip the serialization and restored from snapshot directly then the assertion at the end of the file succeeds.
Expected result
After restoring from serialized persisted snapshot the machine should be able to go back to a history node.
Actual result
The machine could not go to a history node and goes back to the initial state of the machine.
XState version
XState version 5
Description
I think we've discovered unexpected behaviour when restoring from a persisted snapshot that has been serialized and the machine's historyValue not being restored correctly.
Take the following sample checkout machine (link to stately):
Say we go through the following path:
simulated.demo.mov
So far this looks good. The History node successfully remembers the previous "OrderSummary" state by returning to "OrderSummary.Ready" the second time around.
The problem appears to only happen if we persist the state of the machine, serialize it, and restore it.
Steps to reproduce
Start with this minimal reproduction: https://stackblitz.com/github/seanlennaerts/xstate-history-bug?file=README.md&view=editor
If you run it with
npm run test
you'll see that the snapshots for the original actor and the restored actor do not match:The first log is the snapshot from the original actor and the historyValue is an instance of StateNode. The second log is a snapshot of a second actor that restored the serialized state of the first actor and the historyValue is a pojo - I'm thinking this may have something to do with the bug.
So what actually happens when the second actor tries to go back to the OrderSummary history node?
Instead of returning to "OrderSummary.Ready" which the historyValue points to, the machine goes all the way to the initial state "ShippingAddress" - this is where the assertion at the end of the file fails.
Interestingly enough if we skip the serialization and restored from
snapshot
directly then the assertion at the end of the file succeeds.Expected result
After restoring from serialized persisted snapshot the machine should be able to go back to a history node.
Actual result
The machine could not go to a history node and goes back to the initial state of the machine.
Reproduction
https://stackblitz.com/github/seanlennaerts/xstate-history-bug?file=README.md&view=editor
Additional context
No response
The text was updated successfully, but these errors were encountered: