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

Inject $location service cause $rootScope:infdig error on Edge 14.14393 (latest) and Angular 1.5.8 when html5mode is on and the page has an Internationalized Domain Name domain #15217

Closed
xavadu opened this issue Oct 5, 2016 · 9 comments · Fixed by #15235

Comments

@xavadu
Copy link

xavadu commented Oct 5, 2016

Hello,

Yes, as the title define it "Inject $location service cause $rootScope:infdig error on Edge 14.14393 (latest) and Angular 1.5.8 when html5mode is on and the page have an IDN domain" quite specific and quite complicate to find the issue too.

Before go to the detail
It happen only with the latest version of Edge (14.14393) and the latest version of Angular (1.5.8), if we use ng 1.5.8 and a previous version of Edge the problem doesn't happen, the same if we use ng 1.5.5 and the latest version of Edge. So, I am not totally sure if the problem could be on Edge or Angular, but for sure would be possible to have a workaround to avoid it.

How to reproduce the error
Run the following code in a IDN domain and browse the page using Edge (14.4393)

http://jsfiddle.net/Lvc0u55v/10528/

Web console output:

Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.5.8/$rootScope/infdig?p0=10&p1=%5B%5D
   at Scope.prototype.$digest (http://währungsrechner.dev/assets/javascript/all.73777e.js:27780:13)
   at Scope.prototype.$apply (http://währungsrechner.dev/assets/javascript/all.73777e.js:28008:13)
   at done (http://währungsrechner.dev/assets/javascript/all.73777e.js:22049:36)
   at completeRequest (http://währungsrechner.dev/assets/javascript/all.73777e.js:22251:7)
   at requestLoaded (http://währungsrechner.dev/assets/javascript/all.73777e.js:22184:9) undefined
all.73777e.js (24138,11)

SCRIPT5022: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.5.8/$rootScope/infdig?p0=10&p1=%5B%5D
all.73777e.js (28011,13)

If the domain is not an idn domain (doesn't matter if on the cloud or locally) the error doesn't happen.
If the html5mode is not activated, the error doesn't happen.

Posible fix meanwhile
Downgrade Angular to 1.5.5.
If possible doesn't use html5mode.
If possible doesn't use $location service, use window.location instead.

Some links
Edge 14.14393 (latest): https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/ (the version of BrowserStack doesn't throw error because is not the latest)
IDN domain: https://en.wikipedia.org/wiki/Internationalized_domain_name

Since usually Edge is updated automatically to the latest version, this could be a serious bug. Have html5mode activated and use $location service could be a common practice.

Thanks,
J.

@Narretz
Copy link
Contributor

Narretz commented Oct 7, 2016

Hi,
I can reproduce this error with a local setup (same domain as you etc.).
Microsoft Edge 38.14393.0.0 and Microsoft EdgeHTML 14.14393. Angular 1.5.8. What's interesting, in Angular 1.5.6, an error first appears, but it's different:

www.währungsrechner.dev
TypeError: Unable to get property 'replace' of undefined or null reference
   at trimEmptyHash (https://code.angularjs.org/1.5.6/angular.js:12571:3)
   at Anonymous function (https://code.angularjs.org/1.5.6/angular.js:13401:5)
   at invoke (https://code.angularjs.org/1.5.6/angular.js:4708:9)
   at Anonymous function (https://code.angularjs.org/1.5.6/angular.js:4507:13)
   at getService (https://code.angularjs.org/1.5.6/angular.js:4654:11)
   at injectionArgs (https://code.angularjs.org/1.5.6/angular.js:4677:9)
   at invoke (https://code.angularjs.org/1.5.6/angular.js:4700:7)
   at $controllerInit (https://code.angularjs.org/1.5.6/angular.js:10177:11)
   at nodeLinkFn (https://code.angularjs.org/1.5.6/angular.js:9096:11)
   at compositeLinkFn (https://code.angularjs.org/1.5.6/angular.js:8459:13)
angular.js (13642,11)

It looks like at this point, $location.absUrl() is undefined. In 1.5.6, the relevant change seems to come from 743b33a.

Then in 1.5.7, we added this: 294d679 and this

Can you please also report this bug with Microsoft? This could also be a bug on their end.

@Narretz Narretz added this to the 1.5.x milestone Oct 7, 2016
@Narretz Narretz changed the title Inject $location service cause $rootScope:infdig error on Edge 14.14393 (latest) and Angular 1.5.8 when html5mode is on and the page have an IDN domain Inject $location service cause $rootScope:infdig error on Edge 14.14393 (latest) and Angular 1.5.8 when html5mode is on and the page have an Internationalized Domain Name domain Oct 7, 2016
@Narretz Narretz changed the title Inject $location service cause $rootScope:infdig error on Edge 14.14393 (latest) and Angular 1.5.8 when html5mode is on and the page have an Internationalized Domain Name domain Inject $location service cause $rootScope:infdig error on Edge 14.14393 (latest) and Angular 1.5.8 when html5mode is on and the page has an Internationalized Domain Name domain Oct 7, 2016
@Narretz
Copy link
Contributor

Narretz commented Oct 9, 2016

So this is definitely an EdgeBug. We Use string.lastIndexOf(string, 0) as a startsWith alternative. In Edge, when the string contains an Umlaut, this returns -1, but it should return 0. See http://plnkr.co/edit/p8jN3rVsMl6eid17XN7T?p=preview. I am not sure why we don't use indexOf for this. Would be a pretty simple change.

Narretz added a commit to Narretz/angular.js that referenced this issue Oct 9, 2016
@jbedard
Copy link
Collaborator

jbedard commented Oct 9, 2016

I assume lastIndexOf(x, 0) was for performance. The last index starting at 0 will only check if it starts-with. Doing indexOf starting at 0 will then proceed to check at index 1, 2, ... all the way to the end of the string.

Narretz added a commit to Narretz/angular.js that referenced this issue Oct 9, 2016
Internationalized Domain Urls, for example Urls with Umlaut (Ä, Ö, Ü)
cause infinite digest in Edge 38.14393.0.0 because lastIndexOf doesn't
work correctly in this version. indexOf does, though.

Fixes angular#15217
@Narretz
Copy link
Contributor

Narretz commented Oct 9, 2016

That makes sense. We could also use the native startsWith fn if it is available, otherwise fall back to lastIndexOf

@jbedard
Copy link
Collaborator

jbedard commented Oct 9, 2016

Using the native one might be worth it. Depends where this method is used and the likelihood of having long strings. If it's only used on URLs, and not in the digest, then just doing indexOf is probably fine.

@Narretz
Copy link
Contributor

Narretz commented Oct 9, 2016

It's only used on urls, but it's part of the locationWatchFn, but only if the url changed and inside an evalAsync

@gkalpak
Copy link
Member

gkalpak commented Oct 10, 2016

IIRC, we were using indexOf() and changed it to lastIndexOf() as a performance improvement (as @jbedard said). If it's an Edge bug, has it been reported?

@xavadu
Copy link
Author

xavadu commented Oct 10, 2016

Great to see that a workaround from the code side is implementable. I will report the bug in Edge as well.
Thanks

@Narretz
Copy link
Contributor

Narretz commented Oct 10, 2016

Here's the edge bug: https://t.co/vxbg2b4ORJ has been auto created from a tweet :D Ideally, everybody should report or +1 this issue as well, so that it might get some traction.

Narretz added a commit that referenced this issue Oct 17, 2016
Internationalized Domain Urls, for example urls with Umlaut (Ä, Ö, Ü)
cause infinite digest in Edge 38.14393.0.0 because lastIndexOf doesn't
work correctly in this version when the search string is the same as the haystack string.

The patch uses an implementation based on core.js: https://github.com/zloirock/core-js/blob/v2.4.1/modules/es6.string.starts-with.js#L16

Edge Bug: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/9271625/

Fixes #15217
PR #15235
Narretz added a commit that referenced this issue Oct 17, 2016
Internationalized Domain Urls, for example urls with Umlaut (Ä, Ö, Ü)
cause infinite digest in Edge 38.14393.0.0 because lastIndexOf doesn't
work correctly in this version when the search string is the same as the haystack string.

The patch uses an implementation based on core.js: https://github.com/zloirock/core-js/blob/v2.4.1/modules/es6.string.starts-with.js#L16

Edge Bug: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/9271625/

Fixes #15217
PR #15235
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this issue Nov 21, 2016
Internationalized Domain Urls, for example urls with Umlaut (Ä, Ö, Ü)
cause infinite digest in Edge 38.14393.0.0 because lastIndexOf doesn't
work correctly in this version when the search string is the same as the haystack string.

The patch uses an implementation based on core.js: https://github.com/zloirock/core-js/blob/v2.4.1/modules/es6.string.starts-with.js#L16

Edge Bug: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/9271625/

Fixes angular#15217
PR angular#15235
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this issue Nov 21, 2016
Internationalized Domain Urls, for example urls with Umlaut (Ä, Ö, Ü)
cause infinite digest in Edge 38.14393.0.0 because lastIndexOf doesn't
work correctly in this version when the search string is the same as the haystack string.

The patch uses an implementation based on core.js: https://github.com/zloirock/core-js/blob/v2.4.1/modules/es6.string.starts-with.js#L16

Edge Bug: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/9271625/

Fixes angular#15217
PR angular#15235
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this issue Nov 21, 2016
Internationalized Domain Urls, for example urls with Umlaut (Ä, Ö, Ü)
cause infinite digest in Edge 38.14393.0.0 because lastIndexOf doesn't
work correctly in this version when the search string is the same as the haystack string.

The patch uses an implementation based on core.js: https://github.com/zloirock/core-js/blob/v2.4.1/modules/es6.string.starts-with.js#L16

Edge Bug: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/9271625/

Fixes angular#15217
PR angular#15235
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this issue Nov 21, 2016
Internationalized Domain Urls, for example urls with Umlaut (Ä, Ö, Ü)
cause infinite digest in Edge 38.14393.0.0 because lastIndexOf doesn't
work correctly in this version when the search string is the same as the haystack string.

The patch uses an implementation based on core.js: https://github.com/zloirock/core-js/blob/v2.4.1/modules/es6.string.starts-with.js#L16

Edge Bug: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/9271625/

Fixes angular#15217
PR angular#15235
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this issue Nov 21, 2016
Internationalized Domain Urls, for example urls with Umlaut (Ä, Ö, Ü)
cause infinite digest in Edge 38.14393.0.0 because lastIndexOf doesn't
work correctly in this version when the search string is the same as the haystack string.

The patch uses an implementation based on core.js: https://github.com/zloirock/core-js/blob/v2.4.1/modules/es6.string.starts-with.js#L16

Edge Bug: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/9271625/

Fixes angular#15217
PR angular#15235
petebacondarwin pushed a commit that referenced this issue Nov 23, 2016
Internationalized Domain Urls, for example urls with Umlaut (Ä, Ö, Ü)
cause infinite digest in Edge 38.14393.0.0 because lastIndexOf doesn't
work correctly in this version when the search string is the same as the haystack string.

The patch uses an implementation based on core.js: https://github.com/zloirock/core-js/blob/v2.4.1/modules/es6.string.starts-with.js#L16

Edge Bug: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/9271625/

Fixes #15217
PR #15235
petebacondarwin pushed a commit that referenced this issue Nov 24, 2016
Internationalized Domain Urls, for example urls with Umlaut (Ä, Ö, Ü)
cause infinite digest in Edge 38.14393.0.0 because lastIndexOf doesn't
work correctly in this version when the search string is the same as the haystack string.

The patch uses an implementation based on core.js: https://github.com/zloirock/core-js/blob/v2.4.1/modules/es6.string.starts-with.js#L16

Edge Bug: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/9271625/

Fixes #15217
PR #15235
ellimist pushed a commit to ellimist/angular.js that referenced this issue Mar 15, 2017
Internationalized Domain Urls, for example urls with Umlaut (Ä, Ö, Ü)
cause infinite digest in Edge 38.14393.0.0 because lastIndexOf doesn't
work correctly in this version when the search string is the same as the haystack string.

The patch uses an implementation based on core.js: https://github.com/zloirock/core-js/blob/v2.4.1/modules/es6.string.starts-with.js#L16

Edge Bug: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/9271625/

Fixes angular#15217
PR angular#15235
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants