{"action":"opened","issue":{"url":"https://api.github.com/repos/rackt/redux-router/issues/70","labels_url":"https://api.github.com/repos/rackt/redux-router/issues/70/labels{/name}","comments_url":"https://api.github.com/repos/rackt/redux-router/issues/70/comments","events_url":"https://api.github.com/repos/rackt/redux-router/issues/70/events","html_url":"https://github.com/rackt/redux-router/issues/70","id":107506433,"number":70,"title":"Infinite recursion when dispatching action in onEnter hook.","user":{"login":"Furizaa","id":365742,"avatar_url":"https://avatars.githubusercontent.com/u/365742?v=3","gravatar_id":"","url":"https://api.github.com/users/Furizaa","html_url":"https://github.com/Furizaa","followers_url":"https://api.github.com/users/Furizaa/followers","following_url":"https://api.github.com/users/Furizaa/following{/other_user}","gists_url":"https://api.github.com/users/Furizaa/gists{/gist_id}","starred_url":"https://api.github.com/users/Furizaa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Furizaa/subscriptions","organizations_url":"https://api.github.com/users/Furizaa/orgs","repos_url":"https://api.github.com/users/Furizaa/repos","events_url":"https://api.github.com/users/Furizaa/events{/privacy}","received_events_url":"https://api.github.com/users/Furizaa/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-09-21T12:59:02Z","updated_at":"2015-09-21T12:59:02Z","closed_at":null,"body":"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.\r\n\r\nNow this code in redux-router kicks in:\r\n\r\nhttps://github.com/rackt/redux-router/blob/master/src/client.js#L29\r\n\r\n... and replaces the history again (calling onEnter again) ...\r\n\r\nhttps://github.com/rackt/redux-router/blob/master/src/client.js#L37\r\n\r\n... because it didn't had the chance to set `routerState` which initially is set to `undefined` ...\r\n\r\nhttps://github.com/rackt/redux-router/blob/master/src/client.js#L14\r\n\r\n... resulting in an infinite loop.\r\n\r\nJust setting `routerState` before the `replaceHistory` call fixes the loop - but everything still gets called twice.\r\n\r\n```js\r\nstore.subscribe(() => {\r\n  const nextRouterState = routerStateSelector(store.getState());\r\n\r\n  if (\r\n    nextRouterState &&\r\n    !routerStateEquals(routerState, nextRouterState)\r\n  ) {\r\n    const { state, pathname, query } = nextRouterState.location;\r\n    routerState = nextRouterState;\r\n    history.replaceState(state, pathname, query);\r\n  } else {\r\n    routerState = nextRouterState; \r\n  }\r\n});\r\n```\r\n\r\nThere has to be a way to initialise `routerState` with the correct state instead of `undefined` on the first call.\r\n\r\n "}}