acdlite / acdlite/redux-router
Infinite recursion when dispatching action in onEnter hook.
- Langage dominant
- JavaScript
- Étoiles
- 2.3k
- Forks
- 194
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
To initially fill the state of my app on the server, components subscribe to the onEnter hook of their routes. In this static initialisation functions I dispatch some actions.
Now this code in redux-router kicks in:
https://github.com/rackt/redux-router/blob/master/src/client.js#L29
... and replaces the history again (calling onEnter again) ...
https://github.com/rackt/redux-router/blob/master/src/client.js#L37
... because it didn't had the chance to set `routerState` which initially is set to `undefined` ...
https://github.com/rackt/redux-router/blob/master/src/client.js#L14
... resulting in an infinite loop.
Just setting `routerState` before the `replaceHistory` call fixes the loop - but everything still gets called twice.
``` js
store.subscribe(() => {
const nextRouterState = routerStateSelector(store.getState());
if (
nextRouterState &&
!routerStateEquals(routerState, nextRouterState)
) {
const { state, pathname, query } = nextRouterState.location;
routerState = nextRouterState;
history.replaceState(state, pathname, query);
} else {
routerState = nextRouterState;
}
});
```
There has to be a way to initialise `routerState` with the correct state instead of `undefined` on the first call.
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Évaluation
Cette issue n'a pas encore été évaluée.