We have a super weird login bug that appears to be caused by this line in Angular's UpgradeModule, so I have a question about that line.
why is:
var subscription = _this.ngZone.onMicrotaskEmpty.subscribe(function () { return $rootScope.$digest(); });
not something like:
var subscription = _this.ngZone.onMicrotaskEmpty.subscribe(function () {
if($rootScope.$$phase === null){
return $rootScope.$digest();
}
});
?
Why is there no check for the phase of that digest?
Because on line 214 there's even a comment that says
"Run callback in the next VM turn - $interval calls $rootScope.$apply, and running the callback in NgZone will cause a '$digest already in progress' error if it's in the same vm turn"
That code ASSUMES that, because it waited until the next tick, that there isn't a $digest phase still happening.
We're not using $interval, but it is apparently the case that calling those lines without setTimeout will cause the exact error we're seeing, so shouldn't there be SOME kind of phase check happening?
(rather than assuming the timeout fixed the problem)... this seems like a race condition.
the reason this is tagged with both angular AND angularjs is because this is angular's upgrade module. upgrade module uses angularjs within angular.