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

Angular app gets into an infinite digest loop #6799

Closed
bertyhell opened this issue Aug 10, 2016 · 3 comments
Closed

Angular app gets into an infinite digest loop #6799

bertyhell opened this issue Aug 10, 2016 · 3 comments

Comments

@bertyhell
Copy link

  • Electron version: 1.3.2
  • Operating system: Windows 10 64x v1607

I have an offline angular app that i can run with http-server and it works.
But when i switch it over to electron and fix a few issues it gets into an infinite digest loop.
I'm wondering what could cause this since only the environment changed, not the angular code. I read somewhere it could be a template being requested that isn't found because the path should be file:///. Is there any way to verify this.

I also tried to debug the angular unminified code, but i don't understand enough about the watcher list to see which watcher changes value all the time.
These are all the watcher values during the digest cycles:
image

The things that differ between electron and the http-server version are:

// electron
document.write('<base href="file://' + __dirname + '/"/>');
// http-server
document.write('<base href="/"/>');

and

<!-- electron -->
<script>
    window.$ = window.jQuery = require('./js/jquery.js');
    window.bowser = require('./js/bowser.min.js');
</script>

<!-- http-server -->
<script src="./js/jquery.js"></script>
<script src="./js/bowser.min.js"></script>

The exception:

angular.js:13920 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 angular.js:68
    at Scope.$digest (angular.js:17562)
    at Scope.$apply (angular.js:17790)
    at bootstrapApply (angular.js:1761)
    at Object.invoke (angular.js:4718)
    at doBootstrap (angular.js:1759)
    at bootstrap (angular.js:1779)
    at angularInit (angular.js:1664)
    at HTMLDocument.<anonymous> (angular.js:31763)
    at fire (C:\Users\verhe\Documents\storied\resources\pdf\offline\js\jquery.js:3187)(anonymous function) @ angular.js:13920
2016-08-10 10:25:33.150 angular.js:17793 Uncaught 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

image

I know this is hard to debug without more code examples, but i'm just looking for some leads why this would occur in electron and not in an http-server

@bertyhell
Copy link
Author

I've added some logging to the angular digest cycle.
Every --------- is a digest cycle
I output every watch that is dirty or that gets clean.

image

It seems that some services start initializing in the http-server version, but not in electron.

@MarshallOfSound
Copy link
Member

The part that looks wrong to me is this bit

// electron
document.write('<base href="file://' + __dirname + '/"/>');

You can't load a local file:// directory as a source location. (I don't think). Try actually pointing it to index.html or something.

Or even better, you have a full node environment. Just run the http-server inside electron?

@bertyhell
Copy link
Author

bertyhell commented Aug 11, 2016

That is actually a good idea. I'll try that.

With trial and error i was able to narrow down the problem to this line:

$locationProvider.html5Mode(true);

commenting that allowed me to get passed the infinite digest loop

I'll close the issue for now. If disabling the html5mode causes any issues with our ui-router, i'll try your solution or reopen the issue.

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

2 participants