Skip to content

A parent state's resolves are resolved twice when a child state's resolve are rejected on initial run #2641

@Septh

Description

@Septh

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

Consider this scenario:

  • 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
  • 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
  • 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

So, in effect: child state 1 is my "visitors only" zone while child state 2 is my "members only" zone.

Now, assume I am a registered user. When I first launch the app, here's what happens:

  1. root state is resolved, my user profile is loaded
  2. child state 1's resolve is rejected (since I'm a member) and I am redirected to child state 2
  3. root state is resolved again! (and the API to load the profile is called again...)
  4. child state 2' is resolved and successfully activated

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?

Note 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.

I've made a Plunker to demonstrate: https://plnkr.co/edit/Nne19FArvUf0W4JHOtB7

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions