0

I've got an angular application that uses a manually bootstrap so we can load in dependencies before the application starts. This application uses UI-router as well.

Seems as though that when we bootstrap the application on Internet Explorer with our code minified an infinite digest loop occurs when the application bootstraps. The infinite digest loop occurs somewhere in UI-Router and I've narrowed it down to one of the following code snippets (I think).

$urlRouterProvider.otherwise(function ($injector, $location) {
    var $state = $injector.get("$state");
    $state.go("defaultState");
});

And in another section:

$rootScope.$on('$locationChangeSuccess', function (e) {
    e.preventDefault();
    if (hiSessionStorage.get('retry')) {
        $location.url("/" + hiSessionStorage.get('retry'));
        hiSessionStorage.remove('retry');
    }
    $urlRouter.sync();
});

The above code, the $locationChangeSuccess function keeps getting hit, and I'm sure it's connected to the infinite digest.

I know this is a fairly common problem and some people have been able to solve it various ways. I've tried the most common outlined here:

https://github.com/angular-ui/ui-router/issues/600

But the above code uses this technique and it doesn't work.

I've also tried the technique here:

Otherwise on StateProvider

To use an actual "otherwise" state instead of a redirect, but no luck.

In addition, I tried to put the e.preventDefault(); and $urlRouter.sync(); inside the if statement in the $locationChangeSuccess listener, but that screwed up quite a few other things, so I wasn't able to do that.

I have a solution (workaround) to this problem, which I would like to post as an answer (if no one else has answered this before I'm able) because I spent two days solid on this problem before finding a workaround and would prefer others do not share the same pain I experienced.

Community
  • 1
  • 1
Blunderfest
  • 1,854
  • 1
  • 28
  • 46
  • I would expect nothing but problems from this setup. I'm quite sure that the same thing could be done without $locationChangeSuccess. What happens with hiSessionStorage? Why do you do that with it? – Estus Flask Oct 12 '15 at 14:23
  • It's an authentication setup. If the auth token times out and you need to re-authenticate you use the retry token in sessionStorage. – Blunderfest Oct 12 '15 at 14:50
  • Is there a problem with making it global 'resolve' dependency? – Estus Flask Oct 12 '15 at 15:11
  • Not particularly, I know there are some things in our application structure we need to change, but we don't have the time to do that right now. So in absence of that, I would like to understand why this is happening. Especially since it only happens with minified code. – Blunderfest Oct 12 '15 at 15:20
  • You don't have strict DI enabled, do you? Otherwise the minification shouldn't affect anything (except the case when minifier settings are too aggressive). – Estus Flask Oct 12 '15 at 15:30
  • We do not. I changed the minification process to the point where it was no longer minifying, just concatenating the file and the problem still occurred, however, without concatenation it's impossible to reproduce. – Blunderfest Oct 12 '15 at 15:47

0 Answers0