Skip to content

Bug: Delays are not properly restored when machine created from snapshot #5331

@jeromegn

Description

@jeromegn

XState version

XState version 5

Description

When using delays (after: { 1000: "myTarget" }), if the state machine is persisted during a delay and then restored by re-creating it from the snapshot, then the delay will never trigger.

Seems like the delay information is lost when snapshotting.

I've worked around it by using a fromPromise actor with a promise resolving after a setTimeout. The input of that actor is a deadline computed when it is created (Date.now() + delay in ms).

Expected result

The delay should be resumed and possibly trigger its resolution condition if it is past the expected time it should've completed.

Actual result

The delay never resolves and the state machine is stuck forever.

Reproduction

I didn't prepare any, but should be easy?

Additional context

No response

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