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

bug: infinite digest on routing redirects #2638

Closed
calendee opened this issue Nov 28, 2014 · 15 comments
Closed

bug: infinite digest on routing redirects #2638

calendee opened this issue Nov 28, 2014 · 15 comments

Comments

@calendee
Copy link

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

@adamdbradley
Copy link
Contributor

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.

@zarko-tg
Copy link

zarko-tg commented Dec 4, 2014

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.

@calendee
Copy link
Author

calendee commented Dec 4, 2014

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

@adamdbradley
Copy link
Contributor

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?

@calendee
Copy link
Author

calendee commented Dec 9, 2014

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
Copy link
Author

calendee commented Dec 9, 2014

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
Copy link
Author

calendee commented Dec 9, 2014

Actually, as you suggested, this is a problem with the update to Angular.

See this issue : angular/angular.js#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.

@adamdbradley
Copy link
Contributor

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

@calendee
Copy link
Author

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.

@adamdbradley
Copy link
Contributor

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

@cbruun
Copy link

cbruun commented Dec 12, 2014

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
Copy link

cbruun commented Dec 12, 2014

There is a solution found here.

Pass a function to $urlRouterProvider.otherwise.

@calendee
Copy link
Author

@cbruun Nice! Thank you so much!

@zarko-tg
Copy link

@cbruun yep, that did it for me too.

@niyando
Copy link

niyando commented Nov 23, 2015

@cbruun that did it for me. Thanks 🍺

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants