angular / zone.js

Implements Zones for JavaScript
https://github.com/angular/angular/tree/master/packages/zone.js/
MIT License
3.25k stars 407 forks source link

ServiseWorker compatiblitity issues in 0.9.0 #1212

Closed IgorMinar closed 5 years ago

IgorMinar commented 5 years ago

The most recent update to 0.9.0 (in google3 cl/240639288 already rolled-back) broke one of the google3 apps. They have an "unusual" setup where they run Angular with zone.js in a service worker context. Zone.js 0.9.0 breaks in the serviceworker because property-descriptor-legacy.ts:56 directly references XmlHttpRequest[1], which is not available in service workers.

They use "self['__Zone_disable_XHR'] = true" to disable zone's other usages of XHR's and actually use the noop stub for Zone once bootstrapped:

 createPlatformFactory(platformCore, 'xxx_service_worker', [
    {provide: PLATFORM_ID, useValue: 'xxx_service_worker'},
  ])().bootstrapModuleFactory(XXXServiceWorkerModuleNgFactory, {ngZone: 'noop'});

Before re-landing 0.9.0 in google3, let's ensure that we avoid executing that code in service workers.

I'll also follow up with them about why they even load zone.js when then stub it out with noop during bootstrap, but we should still try to avoid breaking them.

[1] https://github.com/angular/zone.js/blob/31d31ceead4a8dfd0b747f1912f98f61c89dceff/lib/browser/property-descriptor-legacy.ts#L45

JiaLiPassion commented 5 years ago

@IgorMinar, got it, I will add check here.