statelyai / xstate

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

Bug: Recreating a machine with children after getPersistedSnapshot results in an inability to persist it again #5077

Open iamquoz opened 2 months ago

iamquoz commented 2 months ago

XState version

XState version 5

Description

Sequence of events: 1) Create a machine with children (either one or multiple of the same type) 2) Create an actor and initialize the children machines through events of their parent 3) Call getPersistsedSnapshot 4) Try to create new actor from that snapshot 5) If you reuse the same object, actor works fine and you can call getPersistedSnapshot on a new actor 6) If you don't reuse it, and instead go through JSON.parse(JSON.serialize(...)), getPersistedSnapshot crashes when calling on a new actor.

Expected result

Restored actors continue to be persistable

Actual result

Restored actors fail to persist their children

Reproduction

https://codesandbox.io/p/devbox/gracious-jerry-njrg8n

Additional context

xstate 5.18.1 (latest)