MicheleBertoli / react-automata

A state machine abstraction for React
MIT License
1.34k stars 60 forks source link

Invariant violation error when componentState changed but not machineState #71

Closed dangh closed 6 years ago

dangh commented 6 years ago

Re-pro: https://codesandbox.io/s/ook0p3y23z

If you click on -> b with error button, the flag is locked and you cannot click on -> b button anymore.

I trace down to these methods:

In handleTransition(), this.isTransitioning is turned on https://github.com/MicheleBertoli/react-automata/blob/dbebfba07987b159670c7b9890f01a687ce2f715/src/withStateMachine.js#L152-L161

In handleComponentDidUpdate(), it supposed to be turned off but it does not because the machineState doesn't change. https://github.com/MicheleBertoli/react-automata/blob/dbebfba07987b159670c7b9890f01a687ce2f715/src/withStateMachine.js#L117-L119

So when another transition triggered, the invariant guard yielded.

MicheleBertoli commented 6 years ago

Good catch, thanks for opening this issue and providing a non-working example. @dangh. The issue is fixed in v4.0.3.