Angular.js: 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

Created on 5 Oct 2016  路  9Comments  路  Source: angular/angular.js

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.

Edge low bug

Most helpful comment

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.

All 9 comments

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 https://github.com/angular/angular.js/commit/743b33ab9d8cdb8aa6ff28028a54ac0023f4dc15.

Then in 1.5.7, we added this: https://github.com/angular/angular.js/commit/294d6793fd0e0781a257e35a165e0c6fde082fe7 and this

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

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.

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.

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

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.

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

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?

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

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ashclarke picture ashclarke  路  3Comments

butchpeters picture butchpeters  路  3Comments

jtorbicki picture jtorbicki  路  3Comments

nosideeffects picture nosideeffects  路  3Comments

kishanmundha picture kishanmundha  路  3Comments