{"action":"created","issue":{"url":"https://api.github.com/repos/angular-ui/ui-router/issues/2641","repository_url":"https://api.github.com/repos/angular-ui/ui-router","labels_url":"https://api.github.com/repos/angular-ui/ui-router/issues/2641/labels{/name}","comments_url":"https://api.github.com/repos/angular-ui/ui-router/issues/2641/comments","events_url":"https://api.github.com/repos/angular-ui/ui-router/issues/2641/events","html_url":"https://github.com/angular-ui/ui-router/issues/2641","id":142929358,"number":2641,"title":"A parent state's resolves are resolved twice when a child state's resolve are rejected on initial run","user":{"login":"Septh","id":11949623,"avatar_url":"https://avatars.githubusercontent.com/u/11949623?v=3","gravatar_id":"","url":"https://api.github.com/users/Septh","html_url":"https://github.com/Septh","followers_url":"https://api.github.com/users/Septh/followers","following_url":"https://api.github.com/users/Septh/following{/other_user}","gists_url":"https://api.github.com/users/Septh/gists{/gist_id}","starred_url":"https://api.github.com/users/Septh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Septh/subscriptions","organizations_url":"https://api.github.com/users/Septh/orgs","repos_url":"https://api.github.com/users/Septh/repos","events_url":"https://api.github.com/users/Septh/events{/privacy}","received_events_url":"https://api.github.com/users/Septh/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-23T11:04:00Z","updated_at":"2016-03-26T01:19:50Z","closed_at":null,"body":"I came across this subtle bug while implementing two distinct \"zones\" in my app -- namely a \"visitors only\" zone and a \"members only\" zone. This is tested with Angular 1.5.1 and UI Router 0.2.18\r\n\r\nConsider this scenario:\r\n- **root state** is an abstract state that dynamically loads (through a resolve) the current user's profile. This resolve is injected into direct child states to make sure they're not instanciated before the profile is finished loading\r\n- **child state 1**'s own resolve checks if the user is registered. If so, the resolve is rejected and the user redirected to **child state 2**\r\n- **child state 2**'s own resolve checks if the user is _not_ registered. If so, the resolve is rejected and the user redirected to **child state 1**\r\n\r\nSo, in effect: **child state 1** is my \"visitors only\" zone while **child state 2** is my \"members only\" zone.\r\n\r\nNow, assume I am a registered user. When I first launch the app, here's what happens:\r\n\r\n1. **root state** is resolved, my user profile is loaded\r\n2. **child state 1**'s resolve is rejected (since I'm a member) and I am redirected to **child state 2**\r\n3. **root state** is resolved again! (and the API to load the profile is called again...)\r\n4. **child state 2**' is resolved and successfully activated\r\n\r\nIn my understanding, step 3 shouldn't happen -- **root**'s already been resolved previously and should not be resolved gain. Or am I getting something wrong?\r\n\r\nNote this only happens on the app's initial launch; if I try to navigate to **state 1** (eg. by clicking an `ui-sref`), then only **state 1**'s resolve is tested and correctly rejected without **root state** being resolved again.\r\n\r\nI've made a Plunker to demonstrate: https://plnkr.co/edit/Nne19FArvUf0W4JHOtB7"},"comment":{"url":"https://api.github.com/repos/angular-ui/ui-router/issues/comments/201644208","html_url":"https://github.com/angular-ui/ui-router/issues/2641#issuecomment-201644208","issue_url":"https://api.github.com/repos/angular-ui/ui-router/issues/2641","id":201644208,"user":{"login":"christopherthielen","id":2053478,"avatar_url":"https://avatars.githubusercontent.com/u/2053478?v=3","gravatar_id":"","url":"https://api.github.com/users/christopherthielen","html_url":"https://github.com/christopherthielen","followers_url":"https://api.github.com/users/christopherthielen/followers","following_url":"https://api.github.com/users/christopherthielen/following{/other_user}","gists_url":"https://api.github.com/users/christopherthielen/gists{/gist_id}","starred_url":"https://api.github.com/users/christopherthielen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/christopherthielen/subscriptions","organizations_url":"https://api.github.com/users/christopherthielen/orgs","repos_url":"https://api.github.com/users/christopherthielen/repos","events_url":"https://api.github.com/users/christopherthielen/events{/privacy}","received_events_url":"https://api.github.com/users/christopherthielen/received_events","type":"User","site_admin":false},"created_at":"2016-03-26T01:19:50Z","updated_at":"2016-03-26T01:19:50Z","body":"Thanks for the plunker!\r\n\r\n> In my understanding, step 3 shouldn't happen -- root's already been resolved previously and should not be resolved gain. Or am I getting something wrong?\r\n\r\nYou are misunderstanding.  The initial transition is cancelled and a brand new one started (when you do your check and redirect).  Think of each transition as atomic; it either happens fully or not at all.\r\n\r\nThe 1.0 release is specifically addressing this use case.  We support redirects from parent to child states while retaining previously resolved values.\r\n\r\nI'll leave this ticket open and make sure it works before 1.0 final"}}