Skip to content

Infinite $digest when cancel route change with hash in the URL #2185

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

Closed
OverZealous opened this issue Aug 18, 2015 · 6 comments
Closed

Infinite $digest when cancel route change with hash in the URL #2185

OverZealous opened this issue Aug 18, 2015 · 6 comments
Assignees

Comments

@OverZealous
Copy link

This requires a bit of setup, but the error can be reproduced here consistently:

Plunker

http://run.plnkr.co/blvlkopDhSwhTwUw/

Setup

  • Use html5mode
  • Switch to any state
  • Add an anchor hash to the URL (critical—the bug only exists in this case)
  • Have a listener on $stateChangeStart that cancels the transition on some event (in my case, I am using it to prevent navigating away with unsaved changes)
  • Infinite $digest cycle triggered

I've tried desperately narrowing down the error, but it the closest I can get is that somehow the $browser is seeing a URL change, even though the URL doesn't change. I think it's related to $urlRouter.update(), which is triggering a $location.url() change.

Other notes:

  • Manually triggering $urlRouter.update() before the cancellation did not seem to help.
  • The example uses $location.hash, but this occurs even if you manually add the hash to the URL, or use history.replaceState.

I'm currently able to work around this issue, but it's rather serious when it happens, because it causes the entire application to crash in my case.

@eddiemonge
Copy link
Contributor

It sounds like a very edge case. Have you tried using the locationChangeStart even as well since you are modifying the url outside of ui-router?

@OverZealous
Copy link
Author

I don't think it's that edge of a case: I need to be able to stop a route change if the user has not saved a form, yet I want to use anchors to jump down to sections on a long form.

Using locationChangeStart won't necessarily help—I need to stop the router from transitioning on change, not the URL. If someone clicks a ui-sref link, that may or may not trigger a location change event.

@eddiemonge
Copy link
Contributor

Can you reproduce this without having to add the hash to the url manually?

@OverZealous
Copy link
Author

I'm not sure what you mean—how else can I add the hash?

The Plunker provided adds the hash via $location. My code is specifically using $window.replaceState, because I'm scrolling up and down the form and setting the hash dynamically, but this is still a legitimate issue, even in that scenario.

@christopherthielen christopherthielen self-assigned this Aug 20, 2015
@christopherthielen
Copy link
Contributor

@OverZealous your plunker is expired (don't link to run.plnkr). Can you try this preview of 0.2.16 release? I suspect it will fix your problem. Reopen if that's not the case.

https://rawgit.com/christopherthielen/5955e75307c6877f0c9d/raw/eb1b923f9e18e265fcf520c29e54b82a9e43b87d/ui-router.0.2.16-pr2.js

See also #2238

@OverZealous
Copy link
Author

Sorry about the plunkr!
This is really weird. I'm no longer getting the infinite digest, but now the entire page reloads!

Here's the Plunkr, it's a little more advanced
(Direct link to run.plunkr.co)

To recreate the issue: click on Add Hash, then check the Prevent Routing checkbox. Finally, click on either Go to B link. Both the added hash and the cancellation must happen, or the refresh doesn't occur.

Note that I'm testing on Firefox, in case that changes things.

I won't reopen this as it's not affecting me right now, and I'm not 100% sure it's not an issue with the Plunkr. Plus it might be a different issue.

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