Packages

xstate

5.33.4 · 7 Nov 2026MIT9M / weekRepositoryHomepagenpmAtom feed

Your version

4.11.0

2 Jul 2020Where it was published

4.38.3 is the newest release of 4.x.

In short

1 breaking1 deprecated1 new1 fixed

  • Breaking

    Improved type inference for InvokeConfig['data']. This has required renaming data property on StateNode instances to doneData. This property was never meant to be a part of the public API, so we don't consider this to be a breaking change.

  • Deprecated

    New property introduced for eventless (transient) transitions: always, which indicates a transition that is always taken when in that state. Empty string transition configs for transient transitions are deprecated in favor of always:

Release note

Minor Changes

  • Breaking

    Improved type inference for InvokeConfig['data']. This has required renaming data property on StateNode instances to doneData. This property was never meant to be a part of the public API, so we don't consider this to be a breaking change.

  • The resolved value of the invoke.data property is now available in the "invoke meta" object, which is passed as the 3rd argument to the service creator in options.services. This will work for all types of invoked services now, including promises, observables, and callbacks.

    const machine = createMachine({
      initial: 'pending',
      context: {
        id: 42
      },
      states: {
        pending: {
          invoke: {
            src: 'fetchUser',
            data: {
              userId: (context) => context.id
            },
            onDone: 'success'
          }
        },
        success: {
          type: 'final'
        }
      }
    },
    {
      services: {
        fetchUser: (ctx, _, { data }) => {
          return fetch(`some/api/user/${data.userId}`)
            .then(response => response.json());
        }
      }
    }
  • Deprecated

    New property introduced for eventless (transient) transitions: always, which indicates a transition that is always taken when in that state. Empty string transition configs for transient transitions are deprecated in favor of always:

    // ...
    states: {
      playing: {
    +   always: [
    +     { target: 'win', cond: 'didPlayerWin' },
    +     { target: 'lose', cond: 'didPlayerLose' },
    +   ],
        on: {
          // ⚠️ Deprecation warning
    -     '': [
    -       { target: 'win', cond: 'didPlayerWin' },
    -       { target: 'lose', cond: 'didPlayerLose' },
    -     ]
        }
      }
    }
    // ...

    The old empty string syntax ('': ...) will continue to work until V5.

Patch Changes

  • StateMachine<any, any, any> is no longer a part of the InvokeConfig type, but rather it creates a union with InvokeConfig in places where it is needed. This change shouldn't affect consumers' code.

A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.