nareshbhatia / mobx-state-router

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

routerState changes twice on transition #71

Closed lukavuletic closed 4 years ago

lukavuletic commented 5 years ago

Recently I have discovered that routerState changes twice on one transition. I have tested it on a completely fresh project (meaning I have created and installed only necessary things to reproduce the case) and on three different projects, all with different configuration. I have tried both observing and having a reaction on routerState, as well as debugging actual sourcecode through chrome dev tools.

Is there a specific reason as to why that happens, and if so, is there a way to react only to one change with ignoring the other one, while still having access to routerState as an object? Also routerState that I'm interested in is the one I am transitioning to.

nareshbhatia commented 4 years ago

Hi @lukavuletic, as far as I can tell, the routerState changes only once on one transition. The easiest way to confirm this is to put a console.log() in RouterStore.setRouterState(). This is the single location where the routerState is changed. After adding this console.log(), I tested with two sample apps: mobx-shop and (animated-transitions)[https://github.com/nareshbhatia/mobx-state-router/tree/master/examples/animated-transitions] - I did not find any issues. One state change per transition. It could be that you are seeing this because of some re-renders outside of mobx-state-router.

Closing this for now. Feel free to reopen if you can prove otherwise.