npm / xstate
xstate
What changed in xstate 5, from its official release notes, upgrade guides and advisories. Sources checked 2026-11-30.
131 breaking52 new APIs and options11 behavior and defaults19 fixes and other
See which of these apply to your code, ranked, in your agent:
npx @unstale/cli initxstate 5213 changes
Breaking changes 131
Targeting a history state that is a direct child of an unvisited parallel state with no default target now enters the parallel state's initial configuration instead of doing nothing.
Action, actor, delay, and guard arguments are consolidated into a single object argument.
Builtin action creators such as assign and sendTo now return functions; users should pass around their returned values without relying on their shape.
Restored state no longer contains actions, which are assumed to have already run; restoration does not replay them.
Actions are no longer called with state.
Activities were removed; implement them as invoked callback services instead.
The actor.batch([...]) method is removed; loop over events and send them individually.
Use actor.getSnapshot() to read the current snapshot; subscribing after start no longer immediately emits it.
actor.onTransition(...) is removed; use actor.subscribe(...).
actor.send() no longer accepts string event types; send an event object instead.
Actor status is no longer publicly available as a property.
Subscribing after an actor has started no longer immediately emits the current snapshot.
The onEvent, onSend, and onChange handlers were removed; use onTransition or subscribe.
Sending requires an event object, and the separate payload argument is no longer supported.
Sending a string event now throws a proper error message.
The method no longer returns the next state and is now a void, fire-and-forget function.
The redundant sender method was removed; use actorRef.send instead.
The services property has been renamed to actors.
machine.transition and machine.getInitialState now require an actorScope argument.
Delayed transitions can no longer be defined using an array; only the object variant is supported.
Internal after event types changed from the parenthesized form to xstate.after.<delay>.<state-id>.
Eventless transitions must use the always property; an empty string can no longer define them.
Always transitions are not selected when the preceding transition does not change machine state, reducing the risk of infinite loops.
Transitions can no longer be configured using arrays; only regular object-based configs are supported.
Assign actions execute in definition order, and later actions reading context see intermediate values; define assigns first to retain the previous behavior.
Executing assign when context is undefined now throws an error instead of issuing a warning.
The autoForward property on invoke configs is removed; send events explicitly instead.
Child state nodes are always re-entered when targeted by transitions defined on compound state nodes; stateIn can prevent undesirable re-entry.
When context types are specified in machine config, the context property is required; context is restricted to an object, and undefined defaults to an empty object.
Machine factories no longer accept context as a third argument, and machine config context no longer accepts a function.
Pass a snapshot in createActor's options to restore actor state; actor.start() no longer accepts a state argument.
The state option was renamed to snapshot.
The Machine(config) function is now called createMachine(config).
The function was removed in favor of strong types in machine configuration.
The actor options property deferEvents was removed.
Use enqueueActions() instead of the removed pure() and choose() methods.
Machine error events are thrown if the actor has no registered error listener.
The escalate action creator is removed; actions can throw errors that propagate and can be handled with an onError transition.
_event was removed from all APIs and types.
Error events now carry error data in event.error instead of event.data.
The interpreter execute option was removed; the interpreter executes actions immediately according to SCXML semantics.
Exit actions are no longer called when a machine is stopped externally, but still run when it reaches its final state.
The transition property external was renamed to reenter.
Callback actors may return only cleanup functions or undefined; returning promises no longer works.
sendBack and receive are now merged with the other properties passed to the callback logic creator.
fromReducer was renamed to fromTransition.
The method was renamed to getPersistedSnapshot.
The cond transition property is now called guard.
Guards now receive a single object argument rather than separate context and event arguments.
Guard objects use the guard property, and guard parameters belong in the params property.
Implementation functions now receive one object argument containing context, event, and other properties.
The in transition property is removed; use guard: stateIn(...) instead.
An error is thrown when a compound state node does not specify an initial state.
Use input to provide data to an actor and derive machine context from it.
Use the inspection API to observe events.
The off method was removed.
The method was removed; use interpreter.subscribe with an error observer.
Use actorRef.subscribe with a complete observer instead.
The invoke.data property is removed; use invoke.input to provide context to invoked actors.
Use invoke.input to provide context to invoked actors.
Use actor logic creators as invoke.src instead of functions.
A string value can no longer be passed directly to invoke; use the object form with src.
Replaces isState and isStateConfig; AnyState is deprecated in favor of AnyMachineSnapshot.
Compound string state values are no longer accepted; use the state value representation instead.
Invalid state values, including values with nonexistent state regions, are no longer handled; rehydrated data must be migrated when the machine schema changes.
The machine property formerly named machine.options is now machine.implementations.
machine.withConfig() has been renamed to machine.provide().
machine.transition(…) now requires an actor scope for its third argument.
The third context argument and direct state-value inputs were removed; pass a resolved MachineSnapshot containing context instead.
Directly overriding context with machine.withContext(...) is no longer supported; use input instead.
The machineConfig.schema property is renamed to machineConfig.types.
machineConfig.tsTypes has been renamed and moved to machineConfig.types.typegen.
The nextEvents property was removed.
The utility function was removed.
The matchState helper function was removed.
The Interpreter method was removed; use State#can to check whether sending an event would lead to a state change.
The previously deprecated configuration property was removed.
The machine's final output is now specified on the machine config's output property rather than on the final state.
The package exports field limits imports to files that are part of the public API.
Action and guard object properties other than type must be nested under params and are passed as the implementation's second argument.
The flag is no longer required because actions are ordered predictably by default; assign actions run in definition order.
Dynamic input and output must use a function rather than an object with property mappers.
Use raise(...) to send events to self.
Delayed event IDs are no longer derived from event types; provide an explicit ID when cancelling a delayed raised event.
Atomic and parallel states are no longer reentered when the target does not escape them; set reenter: true to retain reentry.
The send(...) action creator is removed; use raise(...) for self-directed events or sendTo(...) for other actors.
The batch method was removed.
Invoked and spawned actors are no longer available on service.children; access them from state.children.
The send(type, payload) call shape is no longer supported.
The snapshot.done property is removed; use snapshot.status === 'done', which is available to all actors.
EmittedFrom was renamed to SnapshotFrom.
The imported spawn() function is removed; use spawnChild(...) or the assigner argument's spawn method.
spawn is no longer imported from xstate; obtain it from assign metadata, and actors from implementations can be spawned by name.
Use the spawnChild(...) action creator to create child actors.
The State class was replaced by MachineSnapshot objects, so instanceof State checks no longer work.
The property was removed because actions are transition side effects and are not meant to persist.
Removed State['changed']; matching transitions create a new State instance, while no matching transitions return the current state.
The State event type was removed.
The internal queue property was removed.
The state.configuration property has been renamed to state._nodes.
The state property was removed; obtain the session ID from actor.sessionId.
state.can() no longer accepts string event types; pass an event object instead.
The children property now maps invoked actor IDs to ActorRef instances; actor interfaces use opaque ActorRef references.
The property was renamed to state.nodes.
The property is removed because events are not part of state unless explicitly added to context; use the inspection API to observe events.
The method was removed; use StateMachine#resolveState instead.
The state.meta property has been renamed to state.getMeta().
The state.history property is removed; maintain previous snapshots through actor.subscribe(...).
Its shape now maps state node IDs to historic descendant state nodes, following the SCXML algorithm; it is considered internal.
The state.nextEvents property is removed because it is not a completely safe or reliable way to determine sendable events.
The state.toStrings() method has been removed.
The transitions property was removed from State.
Use the stateIn guard to validate state transitions instead of the removed in transition property.
The isTransient property was removed from StateNode.
StateSchema was removed from all generic type signatures.
The action creator was renamed to stopChild to clarify that a parent can stop only child actors.
Strict mode is removed; use a wildcard transition to throw on unhandled events.
The sync option was removed from invoke and spawn.
Transitions are internal by default rather than external; use reenter: true when the previous re-entry behavior is needed.
Transitions are internal by default; set external: true to reenter the source state when the target lies within it.
The machine schema property is now types, and tsTypes is now types.typegen.
XState v5 requires TypeScript 5.0 or greater; strictNullChecks and skipLibCheck are recommended.
Typestate typings were removed because manually specified state value and context types can describe impossible states.
useActor(logic) now accepts actor logic instead of an existing ActorRef; use useSelector and actor.send with an existing ActorRef.
React hooks no longer accept lazy machine creators or implementations as a second argument; pass machine.provide(...) as the first argument.
The Vue hook returns snapshot instead of state, and actor instead of service.
The default timeout is now Infinity instead of 10 seconds.
Automatically generated events now use the xstate. prefix, with event names such as done.invoke.* changed to xstate.done.actor.*.
Redux dev tools support is no longer the default and can be included from this module.
Done events are now generated recursively for all parallel states on the ancestors path.
The listed helpers and actor creators can now be imported from xstate; the send action export was removed.
New APIs and options 52
Add types.transitionMeta to type transition metadata separately from state metadata; when omitted, types.meta continues to apply to both.
Exports InspectedTransitionEvent from xstate, making it available to developers.
Adds mapState(snapshot, mapper) to map a snapshot to values based on active states.
Adds an option to configure the maximum number of microsteps allowed before throwing an infinite loop error; it defaults to Infinity.
Adds an option to xstate/graph traversal helpers and createTestModel to control which events are explored from each state, enabling enabled-only traversal.
Adds a method that derives a Readable from an actor snapshot, with subscribe and synchronous get access; subscriptions emit only when the selected value changes.
States with route: {} and an explicit id can be navigated to from anywhere using an xstate.route event; routes can also use guards for conditional navigation.
Returns an array of snapshot-and-actions tuples for each microstep in the initial transition.
Returns an array of snapshot-and-actions tuples for each microstep in a transition.
Adds a utility that returns all transitions available from the current state.
Adds a method to incrementally extend machine setup configurations with actions, guards, and delays that can reference base definitions and support chaining.
Action implementations can access action parameters directly as their second argument.
XState v5 adds the ability to create actor systems.
Interop observable symbols were added so actor refs are compatible with libraries such as RxJS.
Higher-level guards now support composing guards with and, or, and not.
The cancel action now supports expressions.
Wildcard transitions can handle unhandled events, including throwing when an event is unknown.
The second argument accepts input data, which is passed in the xstate.init event.
The inspect option lets applications observe actor creation, events sent between actors, and emitted snapshots.
Creates an actor that does nothing, useful for testing and integrations that require an actor when one may be absent.
XState v5 adds deep persistence for invoked and spawned actors.
The new action creator enqueues actions for execution and offers an alternative to pure and choose.
fromCallback is an available actor logic creator.
fromEventObservable is an available actor logic creator.
fromObservable is an available actor logic creator.
fromPromise is an available actor logic creator.
fromTransition is an available actor logic creator.
Use getNextSnapshot(...) to get the next snapshot from actor logic based on a current snapshot and event.
Guard implementations can access guard parameters directly as their second argument.
XState v5 adds higher-level guards.
XState v5 adds an inspect API.
Returns the intermediate MachineSnapshot for a single microstep, without transient transitions or raised events, for debugging.
Invoke configs can define a transition to take when an invoked actor's snapshot updates.
The onSnapshot transition object is supported for invoked machines, observables, promises, and transition functions.
XState v5 adds partial event descriptors, also described as partial wildcards.
Use reenter: true instead of internal: false to specify external transitions.
The self actor reference is available in all action metadata.
Actor logic creators now receive self in their arguments.
The setup API lets developers specify types and strongly typed state values.
setup().createMachine() configures actor, action, guard, and delay implementations for a machine.
The stateIn guard supports checking a combination of an ID and a path.
Actors belong to implicitly created systems that allow actors to be registered and referenced using systemId.
Actor logic creator functions now receive system in their arguments.
Machines can now declare action types, allowing action configurations to be checked for required parameters and unknown action names.
Actor source names, IDs, and logic can now be specified in machine types for stronger typing of invoke configuration and output.
Child IDs can be typed with types.children when using setup.
Machines can now specify delay types.
Machines can now declare their guard types.
Machine input types can now be declared and are strongly typed in the context initializer and actor input.
Machines can now specify output types to strongly type snapshot.output.
Machines can now define strict tag types.
The @xstate/react useInterpret() hook has been renamed to useActorRef().
Behavior and default changes 11
assertEvent now supports partial descriptors, allowing checks for events whose type starts with a given prefix.
Action and guard parameters can now be resolved dynamically.
Snapshots now share status, output, error, and context properties, so actor results are read from a consistent snapshot shape.
The interpret() function has been renamed to createActor().
Spawned actors with a referenced, non-inline source can now be deeply persisted and restored.
A state node's initial configuration can include executable content such as actions.
Partial event descriptors now infer event types safely, including the matching event variants and their fields.
State values and snapshot.matches() arguments are now strongly typed when using the setup API.
Use snapshot.status === 'done' to check completion; status is available to all actors.
Spawn arguments are now strongly typed based on actor types.
Actors can now be spawned directly outside assign action creators.
Fixes and other changes 19
assertEvent now narrows generic event parameters and events whose type is a union of literals, while still rejecting invalid event descriptors.
Partial wildcard descriptors now preserve the bare prefix event in narrowed types, matching runtime behavior; this also applies to event types inferred for partial wildcard transitions.
When an unhandled error from an invoked actor causes a machine to error, remaining invoked and spawned actors are stopped and their cleanup functions called before the machine settles in the error state.
Generic history values, snapshot nodes, and directed graph results now accept arbitrary state and transition metadata consistently, avoiding unsafe-type warnings when inspecting machines through generic APIs.
AnyStateNode, AnyStateNodeDefinition, and AnyTransitionDefinition now widen their metadata parameters to match nodes of an AnyStateMachine, avoiding unsafe-argument and unsafe-return reports.
Machine snapshots retain their machine-specific methods when initialization fails, keeping methods such as snapshot.matches(...) available on error snapshots.
Sending an event containing unserializable data to a stopped actor no longer throws; the development-only warning is emitted safely.
Fixes initialTransition and transition throwing a duplicate system ID error when a machine contains an invoke with a systemId.
When guards on an exact event descriptor all fail, matching wildcard descriptor transitions are now tried as fallback.
Fixes children snapshot union pollution for typed invoke.
Named guards registered with setup({ guards }) are now resolved for route.guard.
Types are exported so setup() declaration emit works.
Fixes cleanup of systemId for nested children when stopChild is used.
Fixes a bug in Cordova when iterating an empty Map.
Actors with the same ID are correctly reinstantiated when stopped and then invoked or spawned again in the same microstep.
Errors thrown in an observer no longer crash actors; they are passed to the observer's error handler, or thrown with a clear stack if none is provided.
Fixed a runtime crash for machines whose root state's type is final.
Inline actions are correctly executed when an equally named action is provided through the implementations argument.
Errors caught during actor execution are consistently included in snapshot.error and reported to the closest error listener.