nareshbhatia / mobx-state-router

MobX-powered router for React apps
https://nareshbhatia.github.io/mobx-state-router/
MIT License
227 stars 31 forks source link

#111 Transition hooks not called for redirects changes #119

Closed dkolarev closed 3 years ago

dkolarev commented 3 years ago

Related to the previously discussed issue with the transition hooks, I made several changes to the router implementation. The transition() function has been moved from the RouterStore to the separate TransitionState class. A new instance of the TransitionState object is created whenever routing occurs. If we preserve a fromState during a transition, calling exit hooks can be problematic and lead to an infinite loop, so we should check that they are executed only once. Still, we have to be aware that because of the recursive implementation of the transition, infinite loops and therefore, stack overflow, can still be caused by a developer. To avoid infinite loops, a simple check has been added and an exception will be thrown whenever an infinite loop is detected.

I have been using the new implementation for a few days on a moderately large project. All tests are passing, the old and new ones.

nareshbhatia commented 3 years ago

@dkolarev, changes look good. I did minor cleanup. Thanks for your contribution!

nareshbhatia commented 3 years ago

mobx-state-router@6.0.0-beta.2 is published with tag "next".

Please test to make sure all is working well.