xstate
5.33.4 · 7 Nov 2026MIT9M / weekRepositoryHomepagenpmAtom feed
4.38.3 is the newest release of 4.x.
In short
3 new5 fixed
Release note
Minor Changes
The
Actiontype was simplified, and as a result, you should see better TypeScript performance.
The
invoke.srcproperty now accepts an object that describes the invoke source with itstypeand other related metadata. This can be read from theservicesoption in themeta.srcargument:const machine = createMachine( { initial: 'searching', states: { searching: { invoke: { src: { type: 'search', endpoint: 'example.com' } // ... } // ... } } }, { services: { search: (context, event, { src }) => { console.log(src); // => { endpoint: 'example.com' } } } } );Specifying a string for
invoke.srcwill continue to work the same; e.g., ifsrc: 'search'was specified, this would be the same assrc: { type: 'search' }.
All
TTypestatetype parameters default to{ value: any; context: TContext }now and the parametrized type is passed correctly between various types which results in more accurate types involving typestates.
Patch Changes
Fixed an issue with initial state of invoked machines being read without custom data passed to them which could lead to a crash when evaluating transient transitions for the initial state.
The "Attempted to spawn an Actor [...] outside of a service. This will have no effect." warnings are now silenced for "lazily spawned" actors, which are actors that aren't immediately active until the function that creates them are called:
// ⚠️ "active" actor - will warn spawn(somePromise); // 🕐 "lazy" actor - won't warn spawn(() => somePromise); // 🕐 machines are also "lazy" - won't warn spawn(someMachine);
It is recommended that all
spawn(...)-ed actors are lazy, to avoid accidentally initializing them e.g., when readingmachine.initialStateor calculating otherwise pure transitions. In V5, this will be enforced.
Fixed a type returned by a
raiseaction - it's nowRaiseAction<TEvent> | SendAction<TContext, AnyEventObject, TEvent>instead ofRaiseAction<TEvent> | SendAction<TContext, TEvent, TEvent>. This makes it comaptible in a broader range of scenarios.
Narrowed the
ServiceConfigtype definition to use a specific event type to prevent compilation errors on strictly-typedMachineOptions.
The JSON definition for
stateNode.invokeobjects will no longer include theonDoneandonErrortransitions, since those transitions are already merged into thetransitionsarray. This solves the issue of reviving a serialized machine from JSON, where before, theonDoneandonErrortransitions for invocations were wrongly duplicated.
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.