Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite $digest Loop on $stateChangeStart redirect if state has templateUrl #2229

Closed
filipesilva opened this issue Sep 6, 2015 · 2 comments

Comments

@filipesilva
Copy link
Contributor

This is a weird error that I've been having on my production app, but found it very hard to accurately reproduce. For now the fix in #600 (comment) works for me.

You can see the error happening on this plunkr: http://plnkr.co/edit/L8DhCNG7cyipBsBypWg3

The app has secure and unsecure states, defined by some extra data on the state definition. On $stateChangeStart I check if the state is marked as secure, and if so, if the current user is authenticated.

If an unauthenticated user is trying to access a secure resource, he gets redirected to the unsecured state.

Upon loading the app, the user is directed to a secured state by default (via $urlRouterProvider.otherwise) because he might already be logged previously.

The problem happens here. A user enters the app, the $stateChangeStart gets fired, I detect he is not authenticated, call event.preventDefault() and $state.go('unsecure-state'). This sends angular into a infinite digest loop bouncing back between the secure and unsecured states.

What makes this odd is that it seems to be dependent on the target state having a templateUrl instead of an inline template. On the plunker, change the template of the secure state from templateUrl: "./unsecure.html" to template: "unsecure" and infinite digest dissapears.

@eddiemonge
Copy link
Contributor

You have to have a state with url: '/' defined. Its weird but documented at #2238
See http://plnkr.co/edit/r6xPdrC7AncxyGGJ4z3K?p=preview

@christopherthielen
Copy link
Contributor

christopherthielen added a commit that referenced this issue Jan 23, 2016
ExpFront pushed a commit to ExpFront/ui-router that referenced this issue Jun 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants