Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork1.3k
Description
XState version
XState version 5
Description
Let say i have a machine like this:
asyncfunctioninvokeMe(){console.log("'next' state: should be second");}constmyMachine=setup({actions:{starting:()=>{console.log("'start' state: should be first");},},actors:{invoker:fromPromise(()=>invokeMe()),},}).createMachine({id:"myMachine",initial:"start",states:{start:{entry:"starting",always:"next",},next:{invoke:{id:"next",src:"invoker",onDone:"complete",},},complete:{type:"final",},},});
Eventhough thestart state is before thenext state, when we run the machine, the order of the console log output was:
'next' state: should be second'start' state: should be first
Expected result
Whatever in thenext state would be executed after thestart state finished with its actions. So the output should be:
'start' state: should be first'next' state: should be second
Actual result
The invoked actor in thenext state was executed before thestart state actions finished.
Reproduction
https://stackblitz.com/edit/github-pusrgdcr
Additional context
In the codesandbox reproduction, the problem doesn't happen if the machine is waiting for the event (i.e: it waits for the user to click the button).
But if theinitial prop of the machine is changed tostart (i.e: it will be transitioned without waiting for any event), then the problem would occur.
p/s: I also created the reproduction in a codesandbox:https://codesandbox.io/p/sandbox/invoke-after-entry-lwqlw6