-
-
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
Stale state when transitioning #323
Comments
Note - if you hit "STOP" a second time then it fully transitions EDIT: See below... after more sleuthing it seems like it's more like multiple transitions are happening and it's going back to the earlier state, as opposed to it only "half transitioning" |
@davidkpiano I believe this is a proper bug (which incidentally was driving me crazy yesterday!) Aside for marking the top-level https://codesandbox.io/s/7499rq7p4x Despite that, the bug may have nothing to do with a sub-invoke... here's a simpler fork which demonstrates the problem with nothing but regular ol' state+transitions: |
Hmmmm... this is weird... I tried creating a test for it in a fork but couldn't duplicate the bug there: |
Ah, nevermind - that weirdness is just because I was ending the test early... I was able to isolate the bug (or maybe expected behavior?) a little better and create a test which passes and fails as explained above... See additional comments here: What happens is that it seems to sortof transition back to This seems odd since there is no actual path from |
@davidkpiano if you want me to make a PR to fold this test in just say the word, though the timeout makes it a little annoying to run the suite... not sure of a cleaner way since the whole point is we want to detect what happened without marking a Also - maybe this whole thing is a documentation issue, i.e. what the expected behavior is in a situation like this? |
seems to me there might also be a related issue of relying on |
no that isn't exactly it... but I do seem to be able to accidentally get in a situation where I have:
Where the onEntry event fires - but listening to the interpreter's state is such that it is NOT foo Same idea as mentioned above but I can't pinpoint how to reliably cause this with a new example :\ |
Are you testing this in the newest version of XState (4.3.x)? These are a little bit hard to follow. I'd appreciate a concise, reproducible failing test case as a PR. |
Yes latest react. Heading to bed but wondering how you want me to improve #323 (comment) ? |
Ah I think I had a different message on my phone asking about latest react before you edited... yes, latest xstate |
Here is a PR with the above test merged... tbh it doesn't perfectly illustrate my current issue but I think it flows from the same bug: #336 |
@davidkpiano - curious, what does your |
That just means that |
This is fixed in 4.3.1 |
In the following test you can see that when you hit the "STOP" button, the
completed
state is entered (as notified via theonEntry
action), but it's also not entered (as reported by theonTransition
listener)https://codesandbox.io/s/vvkrvjxo55
As commented, there is a fix by making the
completed
state "final", though I don't think that should be necessary?It might seem a little biggish for a demo but this was as close as I could make it to the real code I had in my local project and hopefully it's not too out there, tried to keep it minimal but an accurate reflection...
The basic idea is having two levels of
invoke()
and transitioning via theonDone
fired by the sub-machine reaching its final state.The dangling Promise could be the culprit too - in my local project I have a mechanism to force it to resolve and by firing that when the child receives STOP, instead of just transitioning to
end
, it does seem to fix it.Maybe tomorrow I'll create a fork trying to force the promise to resolve and see if that fixes it here too.
(sorry - Github didn't give me the template for some reason.... hope this is okay!)
The text was updated successfully, but these errors were encountered: