Packages

xstate

5.33.4 · 7 Nov 2026MIT9M / weekRepositoryHomepagenpmAtom feed

Your version

201 stable releases, newest first, by release line. Notes are quoted as the maintainers published them.

  1. 5.x · latest line
  2. 5.10.0

    9 Apr 2024
    • The clock and logger specified in the options object of createActor(logic, options) will now propagate to all actors created within the same actor system.

      import { setup, log, createActor } from 'xstate';
      
      const childMachine = setup({
        // ...
      }).createMachine({
        // ...
        // Uses custom logger from root actor
        entry: log('something')
      });
      
      const parentMachine = setup({
        // ...
      }).createMachine({
        // ...
        invoke: {
          src: childMachine
        }
      });
      
      const actor = createActor(parentMachine, {
        logger: (...args) => {
          // custom logger for args
        }
      });
      
      actor.start();
  3. 5.9.1

    2 Mar 2024
    • Add missing emit export

  4. 5.9.0

    1 Mar 2024
    • The new emit(…) action creator emits events that can be received by listeners. Actors are now event emitters.

      import { emit } from 'xstate';
      
      const machine = createMachine({
        // ...
        on: {
          something: {
            actions: emit({
              type: 'emitted',
              some: 'data'
            })
          }
        }
        // ...
      });
      
      const actor = createActor(machine).start();
      
      actor.on('emitted', (event) => {
        console.log(event);
      });
      
      actor.send({ type: 'something' });
      // logs:
      // {
      //   type: 'emitted',
      //   some: 'data'
      // }
    • Added support for params to enqueueActions

  5. 5.8.2

    28 Feb 2024
    • Fixed a type issue that prevent sendParent to be accepted by setup when delays stayed not configured.

  6. 5.8.1

    27 Feb 2024
    • Correctly use falsy outputs (instead of accidentally converting them to undefined).

  7. 5.8.0

    21 Feb 2024
    • Revamped setup and actions types to disallow usage of non-configured implementations

  8. 5.7.1

    17 Feb 2024
    • Removed

      Removed this from machine snapshot methods to fix issues with accessing those methods from union of actors and their snapshots.

  9. 5.7.0

    16 Feb 2024
    • An error will now be thrown if an incompatible state value is passed to machine.resolveState({ value }).

    • You can now inspect microsteps (@xstate.microstep) and actions (@xstate.action):

      const machine = createMachine({
        initial: 'a',
        states: {
          a: {
            on: {
              event: 'b'
            }
          },
          b: {
            entry: 'someAction',
            always: 'c'
          },
          c: {}
        }
      });
      
      const actor = createActor(machine, {
        inspect: (inspEvent) => {
          if (inspEvent.type === '@xstate.microstep') {
            console.log(inspEvent.snapshot);
            // logs:
            // { value: 'a', … }
            // { value: 'b', … }
            // { value: 'c', … }
      
            console.log(inspEvent.event);
            // logs:
            // { type: 'event', … }
          } else if (inspEvent.type === '@xstate.action') {
            console.log(inspEvent.action);
            // logs:
            // { type: 'someAction', … }
          }
        }
      });
      
      actor.start();
      
      actor.send({ type: 'event' });
  10. 5.6.2

    7 Feb 2024
    • You can now import getInitialSnapshot(…) from xstate directly, which is useful for getting a mock of the initial snapshot when interacting with machines (or other actor logic) without createActor(…):

      import { getInitialSnapshot } from 'xstate';
      import { someMachine } from './someMachine';
      
      // Returns the initial snapshot (state) of the machine
      const initialSnapshot = getInitialSnapshot(
        someMachine,
        { name: 'Mateusz' } // optional input
      );
  11. 5.6.1

    5 Feb 2024
    • Fixed compatibility issue of the internal type definitions with TypeScript 5.0

    • Ensure that InteropObservable and InteropSubscribable are present in the type definition file.

    • Add UnknownMachineConfig type

  12. 5.6.0

    29 Jan 2024
    • createActor will now error if the required input is not given to it.

    • The schemas property in setup(...) is now passed through to the resulting machine. This property is meant to be used with future developer tooling, and is typed as unknown for now.

    • Fixed compatibility with the upcoming TypeScript 5.4

  13. 5.5.2

    23 Jan 2024
    • State IDs that have periods in them are now supported if those periods are escaped.

      The motivation is that external tools, such as Stately Studio, may allow users to enter any text into the state ID field. This change allows those tools to escape periods in state IDs, so that they don't conflict with the internal path-based state IDs.

      E.g. if a state ID of "Loading..." is entered into the state ID field, instead of crashing either the external tool and/or the XState state machine, it should be converted by the tool to "Loading\\.\\.\\.", and those periods will be ignored by XState.

  14. 5.5.1

    11 Jan 2024
    • Fixed compatibility with older versions of integration packages.

  15. 5.5.0

    10 Jan 2024
    • Introduce getNextSnapshot(...), which determines the next snapshot for the given actorLogic based on the given snapshot and event.

      If the snapshot is undefined, the initial snapshot of the actorLogic is used.

      import { getNextSnapshot } from 'xstate';
      import { trafficLightMachine } from './trafficLightMachine.ts';
      
      const nextSnapshot = getNextSnapshot(
        trafficLightMachine, // actor logic
        undefined, // snapshot (or initial state if undefined)
        { type: 'TIMER' }
      ); // event object
      
      console.log(nextSnapshot.value);
      // => 'yellow'
      
      const nextSnapshot2 = getNextSnapshot(
        trafficLightMachine, // actor logic
        nextSnapshot, // snapshot
        { type: 'TIMER' }
      ); // event object
      
      console.log(nextSnapshot2.value);
      // =>'red'
    • Allow event in transitions to be narrowed down even when its .type is defined using a union.

  16. 5.4.1

    24 Dec 2023
    • Typegen-based types for detecting missing implementations have been removed internally.

  17. 5.4.0

    22 Dec 2023
    • context factories receive self now so you can immediately pass that as part of the input to spawned actors.

      setup({
        /* ... */
      }).createMachine({
        context: ({ spawn, self }) => {
          return {
            childRef: spawn('child', { input: { parent: self } })
          };
        }
      });
  18. 5.3.1

    18 Dec 2023
    • Update the argument object of enqueueActions(...) to include the self and system properties:

      // ...
      entry: enqueueActions(({ self, system }) => {
        // ...
      });
  19. 5.3.0

    13 Dec 2023
    • Add assertEvent(...) to help provide strong typings for events that can't be easily inferred, such as events in entry and exit actions, or in invoke.input.

      The assertEvent(event, 'someType') function will throw if the event is not the expected type. This ensures that the event is guaranteed to have that type, and assumes that the event object has the expected payload (naturally enforced by TypeScript).

      // ...
      entry: ({ event }) => {
        assertEvent(event, 'greet');
        // event is { type: 'greet'; message: string }
      
        assertEvent(event, ['greet', 'notify']);
        // event is { type: 'greet'; message: string }
        // or { type: 'notify'; message: string; level: 'info' | 'error' }
      },
      exit: ({ event }) => {
        assertEvent(event, 'doNothing');
        // event is { type: 'doNothing' }
      }
    • Fixed an issue with ancestors of the default history target that lie outside of the transition domain being incorrectly entered.

  20. 5.2.1

    9 Dec 2023
    • Update README.md

  21. 5.2.0

    7 Dec 2023
    • Introduce toPromise(actor), which creates a promise from an actor that resolves with the actor snapshot's output when done, or rejects with the actor snapshot's error when it fails.

      import { createMachine, createActor, toPromise } from 'xstate';
      
      const machine = createMachine({
        // ...
        states: {
          // ...
          done: { type: 'final', output: 42 }
        }
      });
      
      const actor = createActor(machine);
      
      actor.start();
      
      const output = await toPromise(actor);
      
      console.log(output);
      // => 42
    • Fixed an issue with spawn within assign not returning a narrowed down ActorRef type on TypeScrip 5.0

    • Fixed an issue that caused a complete listener to be called instead of the error one when the actor was subscribed after being stopped.

  22. 5.1.0

    6 Dec 2023
    • Fix higher-level logic for state machine logic

  23. 5.0.2

    4 Dec 2023
    • Fixed defining actors with input within setup.

  24. 5.0.1

    4 Dec 2023
    • Deprecated

      Flag that docs in this repo are deprecated in favour of docs at stately.ai/docs/xstate

  25. 5.0.0

    1 Dec 2023
    • Breaking

      If context types are specified in the machine config, the context property will now be required:

      // ❌ TS error
      createMachine({
        types: {} as {
          context: { count: number };
        }
        // Missing context property
      });
      
      // ✅ OK
      createMachine({
        types: {} as {
          context: { count: number };
        },
        context: {
          count: 0
        }
      });
    • Breaking

      The third argument of machine.transition(state, event) has been removed. The context should always be given as part of the state.

      // ...
      initial: {
        target: 'someTarget',
        actions: [/* initial actions */]
      }

      This shouldn't change the behavior for most state machines. To maintain the previous behavior, ensure that assign() actions are defined before any other actions.

    • Breaking

      An error will be thrown if an initial state key is not specified for compound state nodes. For example:

      const lightMachine = createMachine({
        id: 'light',
        initial: 'green',
        states: {
          green: {},
          yellow: {},
          red: {
            // Forgotten initial state:
            // initial: 'walk',
            states: {
              walk: {},
              wait: {}
            }
          }
        }
      });

      You will get the error:

      No initial state specified for state node "#light.red". Try adding { initial: "walk" } to the state config.
      
  26. 4.x
  27. 4.38.3

    23 Oct 2023

    Reading the note…

  28. 4.38.2

    27 Jul 2023

    Reading the note…

  29. 4.38.1

    12 Jul 2023

    Reading the note…

  30. 4.38.0

    25 Jun 2023
    • The log, pure, choose, and stop actions were added to the main export:

      import { log, pure, choose, stop } from 'xstate';
  31. 4.37.2

    26 Apr 2023

    Reading the note…

  32. 4.37.1

    23 Mar 2023

    Reading the note…

  33. 4.37.0

    24 Feb 2023
    • The new TagsFrom helper type extracts the type of tags from a state machine when typegen is enabled:

      const machine = createMachine({
        // `tags` attached to machine via typegen
        tsTypes: {} as import('./machine.typegen').Typegen0,
        tags: ['a', 'b'],
        states: {
          idle: { tags: 'c' }
        }
      });
      
      type Tags = TagsFrom<typeof machine>; // 'a' | 'b' | 'c'

      If typegen is not enabled, TagsFrom returns string:

      const machine = createMachine({
        tags: ['a', 'b'],
        states: {
          idle: { tags: 'c' }
        }
      });
      
      type Tags = TagsFrom<typeof machine>; // string
    • Fixed event type narrowing in some of the builtin actions.

  34. 4.36.0

    13 Feb 2023
    • Deprecated

      Deprecated send() action creator. Instead of that, you can use sendTo() to send events to other actors and raise() to send events to the "self" actor.

    • Fixed a class of inference problems for our builtin actions (assign, sendTo, etc).

    • All actions received a new generic: TExpressionEvent. To type things more correctly and allow TS to infer things better we need to distinguish between all events accepted by a machine (TEvent) and the event type that actions are "called" with (TExpressionEvent).

      It's best to rely on type inference so you shouldn't have to specify this generic manually all over the place.

  35. 4.35.4

    30 Jan 2023

    Reading the note…

  36. 4.35.3

    28 Jan 2023

    Reading the note…

  37. 4.35.2

    5 Jan 2023

    Reading the note…

  38. 4.35.1

    19 Dec 2022

    Reading the note…

  39. 4.35.0

    5 Dec 2022
    • The createModel(...) function is now marked as deprecated, as it will be removed in XState version 5. It is recommended to use Typegen instead.

    • Fixed an issue with targeted ancestors not being correctly exited when reented during external transitions.

    • Fixed an issue with external transitions targeting ancestor states. In such a case, entry actions were incorrectly called on the states between the source state and the target state for states that were not reentered within this transition.

  40. 4.34.0

    29 Oct 2022
    • The actions raise and sendTo can now be imported directly from xstate:

      import { raise, sendTo } from 'xstate';
      
      // ...
    • Fixed a regression that has caused machine.getInitialState(value) to not follow always transitions correctly.

  41. 4.33.6

    9 Sep 2022

    Reading the note…

  42. 4.33.5

    1 Sep 2022

    Reading the note…

  43. 4.33.4

    26 Aug 2022

    Reading the note…

  44. 4.33.3

    23 Aug 2022

    Reading the note…

  45. 4.33.2

    15 Aug 2022

    Reading the note…

  46. 4.33.1

    11 Aug 2022

    Reading the note…

  47. 4.33.0

    5 Aug 2022
    • A new predictableActionArguments feature flag has been added that allows you to opt into some fixed behaviors that will be the default in v5. With this flag:

      Please be aware that you might not able to use state from the meta argument when using this flag.

    • All exit actions in the machine will now be correctly resolved and executed when a machine gets stopped or reaches its top-level final state. Previously, the actions were not correctly resolved and that was leading to runtime errors.

      To implement this fix in a reliable way, a new internal event has been introduced: { type: 'xstate.stop' } and when the machine stops its execution, all exit handlers of the current state (i.e. the active state nodes) will be called with that event. You should always assume that an exit handler might be called with that event.

    • Added a dev-only error when forwardTo accidentally ends up trying to forward an event to an undefined actor. Such a situation indicates a logical error and risks an infinite loop.

  48. 4.32.1

    13 May 2022

    Reading the note…

  49. 4.32.0

    6 May 2022
    • Added a StateValueFrom helper that can be used to extract valid state values from a machine. This might specifically be useful with typegen because typegenless state.matches accepts any anyway.

    • Removing the timeout that's built in to waitFor is now supported by explicitly passing an Infinity value.

      Example usage:

      import { waitFor } from 'xstate/lib/waitFor';
      
      // This will
      const loggedInState = await waitFor(
        loginService,
        state => state.hasTag('loggedIn'),
        { timeout: Infinity }
      );

      This fixes a bug that causes waitFor to reject with an error immediately due to the behaviour of setTimeout.

    • Fixed an issue with typegen types not being able to provide events that had a union of strings as their type (such as { type: 'INC' | 'DEC'; value: number; }).

  50. 4.31.0

    8 Apr 2022
    • The waitFor(...) helper function, which asynchronously waits for an actor's emitted value to satisfy a predicate before a timeout, is now available.

      Example usage:

      import { waitFor } from 'xstate/lib/waitFor';
      
      // ...
      const loginService = interpret(loginMachine).start();
      
      const loggedInState = await waitFor(loginService, state =>
        state.hasTag('loggedIn')
      );
      
      loggedInState.hasTag('loggedIn'); // true
    • Subscribing to a stopped interpreter will now always immediately emit its state and call a completion callback.

    • Fixed an issue with state.tags not having correct values when resolving micro transitions (taken in response to raised events). This was creating issues when checking tags in guards.

  51. 4.30.6

    11 Mar 2022

    Reading the note…

  52. 4.30.5

    4 Mar 2022

    Reading the note…

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.