Skip to content

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

Open
@iamquoz

Description

@iamquoz

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions