-
Notifications
You must be signed in to change notification settings - Fork 3k
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 if we do preventDefault() in $stateChangeStart event #600
Comments
Link isn't working "Import Error - Plunk not found!" |
You need to put $stateProvider before your .state calls. Also, this comment makes an untrue assumption:
In fact, /msk/news/smth is not a URL pattern in your state definitions, so it is never going to get there. You might want to redo your plunk. |
I can not defines all incorrect links in states, that's why I have $urlRouterProvider.otherwise('/'). In fact I must to go to start state (url: '/') one time, but I do event.preventDefault() and ui-router try to go to '/' through and through. Now I don't prevent incorrect change if (toState.url !== '/') {
event.preventDefault();
} It works. Can I see $urlRouterProvider.otherwise url into $stateChangeStart handler? For this if (toState.url !== $urlRouterProvider.otherwise.url) {
event.preventDefault();
} |
Bumped into the same bug yesterday. If you get into the $startStateChange handler from $urlRouterProvider.otherwise URL and call preventDefault(), you end up in an infinite loop. The only solution for now was to create a bogus 'startup' state and never prevent going there, and just add $state.go('login') as the only line in the 'startup' state controller, where 'login' is what I actually wanted to put into $urlRouterProvider.otherwise. |
I have probably the same problem here. If the user enters a known url, the otherwise path is not used, the user sees the login page and all is good. So I think it has to do with the otherwise method, and probably combined with the preventDefault call. |
I also had this issue, you can fix it by using the other version of otherwise which takes a function:
|
Was encountering a similar issue. The otherwise's function version did the trick. Thanks @frankwallis 👍 |
@frankwallis thanks! this workaround seems to fix it (no infinite loop YET 😉) |
I have the same issue. Angular 1.3.9 I have also tried by adding the following
but no luck. I have added the following as well to debug:
but they never get called and I still have the infinite loop problem. It seems to be a problem with present/missing / slashes at the end of the url. I have downgraded to angular 1.3.0 and the problem goes away, and everything works as it's supposed to. |
@cgiacomi I recently updated to Angular |
Hi I have just tested with angular 1.3.8 as well and I still have the problem. I have though found that the issue is somehow linked to a redirect to /#/ and that seems to fall into the otherwise callback. I'll try to explain the setup of my routes: routes.js
config.js
What I have noticed is that if, lets say I navigare to localhost:8000
It's like somehow I am redirected to http://localhost:8000/#/ and of course I don't have a route for / which causes the otherwise route to be invoked. Then ofc I end up in the infinite loop. If I remove the otherwise route things work fine. But again with Angular 1.3.0 everything worked fine. Hope that helps, and thanks for the help :) One final thing, if I navigare directly to http://localhost:8000/#/home instead of just http://localhost:8000 then everything works fine. |
Solution of @frankwallis works perfectly on 1.3.6 |
Thnx @frankwallis. Works on ancular 1.3.15, ui-router 0.2.13. |
We're having this issue, too. We don't have a state for '/' and redirect to a initial state, which will end in an infinite digest loop. Using the function call fixes this issue but is quite an ugly hack. |
So what Line 288 in 2fff59c
|
The problem in logic: |
SO EASY. Thanks @frankwallis |
There's something similar wrong with
because it triggers the same iteration counts and similar work around ( a function as second argument in this case). |
@frankwallis solution worked for me too, thanks. It is, anyway, a workaround around a released feature that does not work as intended. Hope it will be fixed soon. |
+1 for @frankwallis workaround. Bailed me out today! |
+1 @frankwallis you made my day! Fixes issue in angular-ui 0.2.13 + angularjs 1.3.13. |
Thinks @frankwallis. Fixes issue in angular-ui-router 0.2.13 + angular1.3.15 |
@frankwallis 👍 Thank you! |
@frankwallis .Thank you! |
@frankwallis +1 |
@frankwallis +1 |
@frankwallis Thank you!! |
@frankwallis +1 |
1 similar comment
@frankwallis +1 |
I have HTML with Login and Logout buttons. On successful login, I am also facing infinite loop issue. Please find attached code. Simple code. Can anyone help me on applying workaround for this issue? |
Amazing that this still isn't fixed. @frankwallis another +1 to you. |
@Blunatic Well, it's a large, widely-used project, so we have a lot to focus on. This isn't high on our priority list because, at first glance, the fix is non-trivial, and what's more, there's a simple, unobtrusive workaround. If it's so 'amazing' to you that we have yet to take time out of our busy schedules to fix it anyway, maybe you could take some time out of yours and start here. 😄 |
@nateabele understandable. Didn't mean to come across as a jerk. My apologies. |
Not at all. Just explaining the rationale. |
Hope you figured things out. I really don't think that's enough context, I'd presume the issue lies somewhere in the adal.login method. |
// the following code will allow you to default to the login , unless your are logged in then it will default to the preferred page. Make sure that the $stateProvider.state .... ; //this must be first otherwise the state object you want to go to wont exist. $urlRouterProvider.otherwise(function ($injector, $location) {
// then in run $rootScope.$on("$stateChangeStart", function (event, toState, toParams, fromState, fromParams) {
|
@frankwallis +1 |
@frankwallis Thank you |
@frankwallis Thanks! You have just ended 2 hours of pain. |
This is still an on going issue. @frankwallis workaround is still the way to go. Wasn't fixed on 0.2.16 as @christopherthielen mentioned. This shouldn't be closed. (cc. @nateabele) |
Wow is this issue really not fixed yet?? |
Noup, it's not. |
@nfantone , thanks for letting me know. cheers. |
… has started Closes angular-ui#2238 Closes angular-ui#2229 Closes angular-ui#2185 Closes angular-ui#2236 Closes angular-ui#2098 Closes angular-ui#600
Almost 3 years later, still experiencing the same issue. Thankfully @frankwallis workaround does the trick. For anybody coming across this issue, here's the workaround (so you don't have to look for it in this long thread):
|
Why $stateChangeStart event fire many times?
http://plnkr.co/edit/QYvRXxciPL9fnyuxiF3l?p=preview
The text was updated successfully, but these errors were encountered: