-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: [V5] Manually Stopping & then Restarting a Machine doesn't trigger it's entry action #4953
Comments
createMachine({
initial: "a",
states: {
a: {
on: {
FOO: "b"
}
},
b: {
entry: ({ event }) => {
// event is gone after transition takes place
// we can't call entry actions again on anothr start
// what event they should be called with?
}
}
},
}) |
@Andarist In my example I am running the event on entering the initial state itself, this works fine with v4, Is there a change between v4 & v5 in how machines handle the entry event? I couldn't find anything in the Documentation about this. This is what I was doing with v4, should we change the approach while upgrading to v5? createMachine({
initial: "a",
states: {
a: {
entry: 'doSomething'
}
},
}) |
A restarted machine like this doesn't completely forget its previous snapshot. When u start again u don't start completely from scratch. If you want to start from scratch then it would be best to create a new instance of this actor. |
Ok, so this is different from how Thanks, I will try to find a different approach but do you think this might be something that can be a possibility in the future as by stopping a machine you would expect it to destroy itself & then restart from scratch like interpret did. |
This would require persisting which effects (actions, invocations) were executed. This may be possible with the future "transition API" #4954 |
@Andarist maybe this is already explained somewhere, but is there a reason why the |
@andrecrimb currently actors are not exactly suited for reuse, so you shouldn't do smth like const snapshot = actorRef.getPersistedSnapshot()
actorRef.stop()
const newActorRef = createActor(machine, { snapshot }) |
XState version
XState version 5
Description
In V4, I manually started and stopped the machine based on certain conditions, which worked correctly (see the provided CodeSandbox link below).
Problem: In V5, while the machine starts correctly for the first time, it fails to trigger the
entry
action when manually stopped and started again. Theentry
action in theinitial
state does not execute on the second attempt to start the machine.Steps to Reproduce: (check output in console)
V4 Example: https://codesandbox.io/p/sandbox/xstate-v4-start-stop-l2xrs6
V5 Example: https://codesandbox.io/p/sandbox/xstate-v5-start-stop-t5xld6
Expected result
The machine should reset on
stop()
& The entry action in the initial state should trigger each time the machine is started.Actual result
The
entry
action does not trigger on the second start.Reproduction
https://codesandbox.io/p/sandbox/xstate-v5-start-stop-t5xld6
Additional context
No response
The text was updated successfully, but these errors were encountered: