0

Background, have an app built originally with angularjs, it's now a angularjs/ angular hybrid using the UpgradeModule. There's been kind of an ongoing problem with falling out of the angular zone and ending up in the <root> zone. Have hit on a fairly repeatable example.

Have hit a rather frequently re-occuring problem of getting stuck in the <root> zone and it's been distilled down to this. So, 3 methods of creating promises, all starting in the angular zone.

new Promise(blahblah)

returns ZoneAwarePromise

new $q(blahblah)

returns Promise

let def = $q.defer(); return def.promise

returns Promise

So, this looks to me like $q promises are not getting patched with zone and so the angular zone is not being maintained and callbacks end up in <root>. Which results in things on the angular half being quite slow (once this has occurred) and occasional digest errors when something runs an apply/ digest in the callback of a promise from some sort of remote request. Common culprits are $http and callbacks from the angularfire library, etc.

So...put simply, is the UpgradeModule intended to patch angularjs promises ($q) as ZoneAwarePromise's? It's what I would have expected.

EDIT: Here is a more barebones example on StackBlitz. This example is showing the same as in my app: The UpgradeModule does not patch $q promises: https://stackblitz.com/edit/github-fwbk4x?file=src%2Fapp%2Fhome%2Fapp.component.ts

lTyl
  • 156
  • 4
  • Convert a `$q` promise to an ES6 promise with `Promise.resolve($qPromise)`. Convert an ES6 promise to a $q promise with `$q.resolve(es6Promise)`. Only `$q` promises are integrated with the AngularJS event processing loop. Only operations which are applied in the AngularJS execution context will benefit from AngularJS data-binding, exception handling, property watching, etc. – georgeawg Apr 02 '19 at 17:35
  • I appreciate the comment! I am failing to grasp how this is relevant to the question though? – lTyl Apr 02 '19 at 17:55
  • ZoneJS works by monkey patching ES6 promises. It does not monkey patch AngularJS promises. That is likely the source of events falling out of zone. – georgeawg Apr 03 '19 at 00:29
  • Yes, that is why it is falling out of zone. The question was: "Is the UpgradeModule intended to patch angularjs promises ($q) as ZoneAwarePromise?" Was the intention that $q promises were supposed to be patched by the AngularTeam (At which point, it is a bug) or was the intention to NOT patch deliberate? (In which case, do you know why?) – lTyl Apr 03 '19 at 01:42
  • File a bug report at https://github.com/angular/angular.js/issues The AngularJS team knows better than me. My take is that Angular 2+ code should not consume $q promises. It should convert them to ES6 promises with `Promise.resolve`. – georgeawg Apr 03 '19 at 02:45

0 Answers0