Xstate: Transitioning to an ID from nested state does not fire parents onExit actions

Created on 3 May 2018  Â·  4Comments  Â·  Source: davidkpiano/xstate

Bug or feature request?

Bug, probably

Description:

When transitioning from a child state to another state on higher level using an ID, the onExit actions of the parent on the same level as the state being transitioned to are not fired.

(Bug) Expected result:

onExit actions of parent state to be called

(Bug) Actual result:

onExit actions are not being called

Link to reproduction or proof-of-concept:

https://codepen.io/MiChAeLoKGB/pen/vjZvMg

This is related to #93 and I am not 100% sure if this is trully a bug, or just how the transitions between states are implemented (ie. they do not bubble).
If you dont use ID's, it calls the "parents" actions, because you have to have the on.SUCCESS in the parent itself (so the onExit and onEntry are the actions of that state).

Question is, which behavior is the correct one.
I would expect it to bubble up, just like the transitions do (if there is no SUCCESS on the child, it bubbles to the parent which has it).

Looking at the documentation of the onExit action, it should indeed be fired in this case:

When the state is a leaf state and is exited to go to a different state
> When the state is a parent state and the next state goes to a different same-level parent
When the state explicitly transitions to itself
bug

Most helpful comment

Fixed in master! (Hooray for refactoring magically fixing problems 🎉)

All 4 comments

The algorithm is currently being refactored internally, so I'm reworking how actions are determined, and it's likely that this bug (and #93) will be fixed in that refactor.

It does seem to be a bug. I exposed it in the debugger: https://bit.ly/2JU4G5I — The codepen had a little typo with onEnty instead of onEntry and when that's fixed, the _entry_ handlers are included, but the exit handlers are indeed not.

Here's a pending test that (hopefully after that refactor) will pass ensuring that the exit handlers are called: https://github.com/davidkpiano/xstate/blob/875c9ad67227d2c5b097772cc78f2506d5f25bbd/test/deep.test.ts#L106-L112

Thanks for the info about the typo, I was confused as to why my live code does fire then onEntry actions, but not the test code...

I have edited the question and fixed the codepen.

Fixed in master! (Hooray for refactoring magically fixing problems 🎉)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rodinhart picture rodinhart  Â·  3Comments

suku-h picture suku-h  Â·  3Comments

greggman picture greggman  Â·  3Comments

bradwoods picture bradwoods  Â·  3Comments

dakom picture dakom  Â·  3Comments