Packages

xstate

5.33.4 · 7 Nov 2026MIT9M / weekRepositoryHomepagenpmAtom feed

Your version

4.23.0

16 Jul 2021Where it was published

4.38.3 is the newest release of 4.x.

In short

4 new1 fixed

Release note

Minor Changes

  • There is a new .preserveActionOrder (default: false) setting in the machine configuration that preserves the order of actions when set to true. Normally, actions are executed in order except for assign(...) actions, which are prioritized and executed first. When .preserveActionOrder is set to true, assign(...) actions will not be prioritized, and will instead run in order. As a result, actions will capture the intermediate context values instead of the resulting context value from all assign(...) actions.

    // With `.preserveActionOrder: true`
    const machine = createMachine({
      context: { count: 0 },
      entry: [
        ctx => console.log(ctx.count), // 0
        assign({ count: ctx => ctx.count + 1 }),
        ctx => console.log(ctx.count), // 1
        assign({ count: ctx => ctx.count + 1 }),
        ctx => console.log(ctx.count) // 2
      ],
      preserveActionOrder: true
    });
    
    // With `.preserveActionOrder: false` (default)
    const machine = createMachine({
      context: { count: 0 },
      entry: [
        ctx => console.log(ctx.count), // 2
        assign({ count: ctx => ctx.count + 1 }),
        ctx => console.log(ctx.count), // 2
        assign({ count: ctx => ctx.count + 1 }),
        ctx => console.log(ctx.count) // 2
      ]
      // preserveActionOrder: false
    });

Patch Changes

  • Add type for Symbol.observable to the Interpreter to improve the compatibility with RxJS.

  • Existing actors can now be identified in spawn(...) calls by providing an id. This allows them to be referenced by string:

    const machine = createMachine({
      context: () => ({
        someRef: spawn(someExistingRef, 'something')
      }),
      on: {
        SOME_EVENT: {
          actions: send('AN_EVENT', { to: 'something' })
        }
      }
    });
  • There are two new helper types for extracting context and event types:

    • ContextFrom<T> which extracts the context from any type that uses context

    • EventFrom<T> which extracts the event type (which extends EventObject) from any type which uses events

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.