bug: infinite digest on routing redirects
Type: bug
Platform: all
Using $stateChangeStart to check authentication status causes infinite digest
To reproduce this, you must use Ionic CLI to create a local app. The problem will NOT be demonstrated in Codepen(not sure why).
So, do the following :
- ionic start digestProblem http://codepen.io/calendee/pen/zxGRza
- cd digestProblem
- ionic serve 9000 9001 (or whatever your preference)
- Note that the app works just fine. You were heading towards /tab/home and got redirected to /signin because the auth check always returns false.
- Now, replace the Beta 13 files in www/lib/ionic with nightlies
- Open the console in your browser. You'll still be on the signin page
- Reload the browser at http://localhost:9000
- Notice that the app is repeatedly trying to access /tab/home even though you are redirecting to signin.
- Finally, angular kills the digests and you end up in the signin state
- Notice that even if you comment out the $state.go("signin");, the app is still constantly trying to reload /tab/home
Sorry but the codepen isn't working. One thing I'm starting to wonder if this is a difference between angular 1.2 and 1.3.
Sounds very much like what I've seen on my side. Apparently not causing any obvious (permanent) breakage of the app in question but just acting up weird as you described. I suspect it could be because of the Angular upgrade. Will keep an eye.
@adamdbradley Sorry about that. Bad link.
Here's a good example : http://codepen.io/calendee/pen/zxGRza
Please remember after changing to the newest Ionic nightly, you must change the URL to http://localhost:9000.
When I use beta13 it sometimes would have the infinite loop, and sometimes not. When I use nightly it was always in an infinite loop. But when I comment out event.preventDefault(); it doesn't have any issues. What's the reasoning for preventing default?
without the event.preventDefault(), the state changes to the originally intended path. The goal is to intercept that path and redirect to somewhere else. Even though the code tries to do this with $state.go, the original state transition occurs and the attempt at redirect fails.
FYI : See the ui-router docs on this : http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$state
Fired when the state transition begins. You can use event.preventDefault() to prevent the transition from happening and then the transition promise will be rejected with a 'transition prevented' value.
Actually, as you suggested, this is a problem with the update to Angular.
See this issue : https://github.com/angular/angular.js/issues/10228
Originally, my config.xml looked like : <content src="index.html">
I solved my issue by doing this in config.xml:
<content src="index.html/#/main/home"/>
Now, the app loads instantly to the correct page after identifying not authenticated.
Any change of getting Angular 1.3.6 included in Ionic bundle? Then, I can see if that solves the overall problem. If that's not in the works prior to Beta 14, that's fine. Just go ahead and close this issue.
I just updated to angular 1.3.6, hopefully that solves it! Thanks
Just updated to Ionic 888 with Angular 1.3.6. It didn't help - the infinite digest is still there but I just don't care anymore. My fix with config.xml works well enough.
Well that's a bummer, strange it does this for your app. However, the idea of using <content src="index.html/#/main/home"/> is a pretty good one, I wonder if we could incorporate automatically loading the $urlRouterProvider.otherwise('/whatever'); into our CLI build's config file so there's less for the device to figure out and redirect to on startup. cc/ @jbavari
The <content src="index.html/#/main/home"/> fix does not work on Android. The browser says it cannot find the file. Tested on Android 4.4.2. Works on iOS.
@cbruun Nice! Thank you so much!
@cbruun yep, that did it for me too.
@cbruun that did it for me. Thanks :beer: