Description
When transitioning a child state node with an onDone transition, and then moving to a new state node and moving back via history - we are sent to the wrong state.
I think what's going on there is that the history key is correct, but the historyValue key is the one being used when moving back into a state node (see video).
Expected Result
I expect that when entering a state via a history node I will be placed in the last node.
Actual Result
I'm put in the closed node first when going back to step1. Note in this example I end up in the correct node, but it's going through the incorrect one to get there (because I have an onDone transition).
Reproduction
https://xstate.js.org/viz/?gist=92bd1d02e733f8a7ae7f19ab97cb2e27
https://www.loom.com/share/35afee664f6d4a538bd421cb6059a999
In the video you'll notice there's a console message that says entered closed state followed quickly by an entered open state message. This happens initially which is expected if you look at the model, but what's not expected is that after moving to step2 and coming back, we see the entered closed state message again. I expect to only see the entered open state message.
Additional context
It's a bit of an awkward example because there's an onDone event which moves .question1 from closed to open. The reason I'm doing this is because in my real use-case I have multiple questions (which are parallel) and I want to trigger a single onDone when they're all finished (and then reset them to open so I can trigger them again later).
I know there may be an anti-pattern with the use of onDone open to suggestions on that. Regardless - it still seemed like a bug to me.
Thanks 馃憤
I need to analyze this thoroughly later to see what is expected. I'm currently re-implementing core algorithm so I'll make sure to check this when I'm done.
By a quick look - it indeed seems like a bug. The last value before exiting the state with history state should be recorded and entered later when entering a history state.
I'm leaving a codesandbox here for myself - https://codesandbox.io/s/blissful-goodall-cw2jf - as it's easier for me to debug this, than in the visualizer. Thanks for the repro case!
Sideways note - I would consider it to be rather a quirky pattern to transition on a done event to a descendant state.
Thanks @Andarist - agreed that the pattern here is a little awkward but it sort of seemed like that had something to do with the bug. I鈥檒l try to find a more straightforward scenario which gives a similar result.
Here's an example where things work properly, probably no surprise to you that moving from closed to open via actions has the desired effect.
https://xstate.js.org/viz/?gist=9d34b690e5738d2d57c593768adc580e
History is being reworked in V5, so this should be already fixed in the next branch.
Most helpful comment
I need to analyze this thoroughly later to see what is expected. I'm currently re-implementing core algorithm so I'll make sure to check this when I'm done.
By a quick look - it indeed seems like a bug. The last value before exiting the state with history state should be recorded and entered later when entering a history state.
I'm leaving a codesandbox here for myself - https://codesandbox.io/s/blissful-goodall-cw2jf - as it's easier for me to debug this, than in the visualizer. Thanks for the repro case!
Sideways note - I would consider it to be rather a quirky pattern to transition on a done event to a descendant state.