{"action":"created","issue":{"url":"https://api.github.com/repos/rackt/react-router/issues/1613","labels_url":"https://api.github.com/repos/rackt/react-router/issues/1613/labels{/name}","comments_url":"https://api.github.com/repos/rackt/react-router/issues/1613/comments","events_url":"https://api.github.com/repos/rackt/react-router/issues/1613/events","html_url":"https://github.com/rackt/react-router/issues/1613","id":97386860,"number":1613,"title":"willTransitionFrom() called infinitely when transition.abort() called","user":{"login":"mindjuice","id":934638,"avatar_url":"https://avatars.githubusercontent.com/u/934638?v=3","gravatar_id":"","url":"https://api.github.com/users/mindjuice","html_url":"https://github.com/mindjuice","followers_url":"https://api.github.com/users/mindjuice/followers","following_url":"https://api.github.com/users/mindjuice/following{/other_user}","gists_url":"https://api.github.com/users/mindjuice/gists{/gist_id}","starred_url":"https://api.github.com/users/mindjuice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mindjuice/subscriptions","organizations_url":"https://api.github.com/users/mindjuice/orgs","repos_url":"https://api.github.com/users/mindjuice/repos","events_url":"https://api.github.com/users/mindjuice/events{/privacy}","received_events_url":"https://api.github.com/users/mindjuice/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-07-27T05:02:37Z","updated_at":"2015-07-30T05:44:34Z","closed_at":null,"body":"I have a pretty standard ``willTransitionFrom()`` in one of my components as below:\r\n\r\n    statics: {\r\n      willTransitionFrom: function(transition, component) {\r\n        if (component.state.dirty) {\r\n          if (!window.confirm('You have unsaved changes.  If you continue, you will lose your changes.')) {\r\n            transition.abort();\r\n          }\r\n        }\r\n      }\r\n    },\r\n\r\nI also have a Cancel button that calls ``this.goBack()``.  Clicking the button causes my ``willTransitionFrom()`` to be called as expected.  If I click the Cancel button in the system dialog though to stay on the page, instead of just leaving me on the page, ``willTransitionFrom()`` gets called again and shows the dialog again.  Clicking Cancel always brings the dialog back up in an infinite loop.\r\n\r\nClicking OK allows the transition to continue as expected, but makes the dialog rather pointless.\r\n\r\nTracing down, I see that react-router ends up calling ``window.history.back()``, which triggers ``onPopState`` again, which ends up calling my ``willTransitionFrom()`` again.\r\n\r\nIs this a bug or am I missing something in my code?"},"comment":{"url":"https://api.github.com/repos/rackt/react-router/issues/comments/126192950","html_url":"https://github.com/rackt/react-router/issues/1613#issuecomment-126192950","issue_url":"https://api.github.com/repos/rackt/react-router/issues/1613","id":126192950,"user":{"login":"mindjuice","id":934638,"avatar_url":"https://avatars.githubusercontent.com/u/934638?v=3","gravatar_id":"","url":"https://api.github.com/users/mindjuice","html_url":"https://github.com/mindjuice","followers_url":"https://api.github.com/users/mindjuice/followers","following_url":"https://api.github.com/users/mindjuice/following{/other_user}","gists_url":"https://api.github.com/users/mindjuice/gists{/gist_id}","starred_url":"https://api.github.com/users/mindjuice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mindjuice/subscriptions","organizations_url":"https://api.github.com/users/mindjuice/orgs","repos_url":"https://api.github.com/users/mindjuice/repos","events_url":"https://api.github.com/users/mindjuice/events{/privacy}","received_events_url":"https://api.github.com/users/mindjuice/received_events","type":"User","site_admin":false},"created_at":"2015-07-30T05:44:34Z","updated_at":"2015-07-30T05:44:34Z","body":"Sigh...so ``redirect()`` has a similar side effect to ``cancel()``.\r\n\r\nIf my history was A, B, C, D and I hit Cancel, D gets popped off, and C becomes the current route.  Then my ``willTransitionFrom()`` hook is called, which calls ``redirect(D)``, so D replaces C.  The history becomes A, B, D instead of A, B, C, D.\r\n\r\nDoing this over and over eventually will clear the history.\r\n\r\nI think ``transition.abort()`` just needs to be fixed, but I'm not sure what to do at this point to fix it.  Cancel doesn't work.  Redirect doesn't work.  Doing nothing doesn't work.  Essentially it needs to push back whatever it popped (or avoid popping it in the first place), but that info doesn't seem to be available anymore.\r\n\r\nCould the code be changed to call ``willTransitionFrom()`` before popping the current entry?  The having ``handleAbort()`` just do nothing would be correct."}}