ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

bug: infinite digest on routing redirects

Open calendee opened this issue 12 years ago • 15 comments

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

calendee avatar Nov 28 '14 15:11 calendee

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.

adamdbradley avatar Dec 04 '14 03:12 adamdbradley

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.

zarko-tg avatar Dec 04 '14 08:12 zarko-tg

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

calendee avatar Dec 04 '14 12:12 calendee

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?

adamdbradley avatar Dec 07 '14 02:12 adamdbradley

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.

calendee avatar Dec 09 '14 10:12 calendee

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.

calendee avatar Dec 09 '14 11:12 calendee

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.

calendee avatar Dec 09 '14 11:12 calendee

I just updated to angular 1.3.6, hopefully that solves it! Thanks

adamdbradley avatar Dec 11 '14 16:12 adamdbradley

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.

calendee avatar Dec 11 '14 16:12 calendee

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

adamdbradley avatar Dec 11 '14 17:12 adamdbradley

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 avatar Dec 12 '14 09:12 cbruun

There is a solution found here.

Pass a function to $urlRouterProvider.otherwise.

cbruun avatar Dec 12 '14 10:12 cbruun

@cbruun Nice! Thank you so much!

calendee avatar Dec 12 '14 14:12 calendee

@cbruun yep, that did it for me too.

zarko-tg avatar Dec 12 '14 14:12 zarko-tg

@cbruun that did it for me. Thanks :beer:

niyando avatar Nov 23 '15 10:11 niyando