Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

$location + history.pushState = $digest infinite loop #3924

Closed
agentcooper opened this issue Sep 8, 2013 · 17 comments
Closed

$location + history.pushState = $digest infinite loop #3924

agentcooper opened this issue Sep 8, 2013 · 17 comments

Comments

@agentcooper
Copy link
Contributor

Here is the test-case: http://jsbin.com/IxAGEzI/1/

We used Angular on page with some old code, which uses history.pushState to change the url at some point. After that, when entering digest loop, it goes crazy and "Infinite $digest Loop" error happens.

So should Angular work fine in that situation or not?

@petebacondarwin
Copy link
Member

This appears to be a bug in $location. It seems that since you are changing the URL outside angular, the $location service thinks that it should change it back to what it was before (since it is different). But inside $browser.url() it finds that the "new" url is the same as $location's "old" url and so doesn't change the url.

Then on the next turn of the $digest loop it does it again, and again, and again, etc.

We need a way to manage this situation in a stable manner.

@fraywing
Copy link

fraywing commented Sep 9, 2013

This is the exact issue i'm having in my issue as well:
#3915

I totally agree that there should be a better way to manage this situation, it seems like a common and growing recurring problem.

@thebigredgeek
Copy link
Contributor

You're test case is a bit buggy. Could you possible address some of the errors?

Uncaught ReferenceError: remoteWindow is not defined

@thebigredgeek
Copy link
Contributor

@petebacondarwin , would a dirty check of window.location vs $location solve this? Where Angular defaults to window.location and sets $location to that when there are conflicts?

@wlingke
Copy link

wlingke commented Nov 20, 2013

We kept running into this error too. A work around we implemented to handle changing the URL but not anything else was to use $location.path to change the URL, then listening for $routeChangeStart and then using event.preventDefault(). This'll change the URL but stop anything else from happening. You can also do this with $stateChangeStart if you're using Angular UI Router.

Nice thing about this versus pushstate is that it works on ie 8 and 9 without having to use history.js

@gigablox
Copy link

gigablox commented Jan 6, 2014

For anyone else that needs a hack to get by I have a little write up here: angular-ui/ui-router#562 (comment)

@julianjelfs
Copy link

This is affecting us too. A fix would be very nice.

@tmaximini
Copy link

Same here, trying to update URL without trashing controllers (btw. it works well when used from the dev console, but gets crazy when using from angular code)

@shadda
Copy link

shadda commented May 15, 2014

Just ran into this as well. Any solid workarounds?

@josebalius
Copy link

Same thing here, anything reliable out there?

@denoww
Copy link

denoww commented Jun 24, 2014

same problem =/

@ryanjohnvelasco
Copy link

Temporary fix: Tested for angularjs on browsers.
it does an infinite loop based on petebacondarwin, so to overcome that

  1. set your new url in $location
  2. $location.replace();
  3. window.history.pushState(null,'any', $location.absUrl());

@denoww
Copy link

denoww commented Jul 10, 2014

I has infinite loop with this in Iphone and Ipad.
Not solved yet =/

2014-07-10 8:26 GMT-03:00 ryanjohnvelasco notifications@github.com:

Temporary fix

  1. $location.replace();
  2. window.history.pushState(null,'any', $location.absUrl());


Reply to this email directly or view it on GitHub
#3924 (comment).

Rodrigo Mendonça

@tbosch
Copy link
Contributor

tbosch commented Aug 27, 2014

Hi, this is a dupe of #6976 which was just fixed.

@tbosch tbosch closed this as completed Aug 27, 2014
@tbosch
Copy link
Contributor

tbosch commented Aug 27, 2014

See 3be00df.

@aygee
Copy link

aygee commented Sep 24, 2014

This is still happening on v1.2.25 which has your fix above I believe @tbosch.

@chrisirhc
Copy link
Contributor

@aygee , you might be running into #9235 . See if that #9237 fixes it for you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.