Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

patchEventTargetMethods is no longer reachable before patches on EventTarget #991

@marinho

Description

@marinho

I'm experiencing an issue when trying to upgrade to newer Angular/Zone versions and just found out that #748 caused it. I will try to describe below with details as possible:

in my job, we have to shit apps wrapped by an internal platform that patches XMLHttpRequest before Zone.js is loaded. Such library is patching addEventListener and other methods and preventing delegation. So, that makes Zone break, as it relies on delegate to let XMLHttpRequest be patched via EventTarget.

That's not under my team's feasability to change, so, we solved that with this:

require('zone.js/lib/zone');
const patchEventTargetMethods = require('zone.js/lib/common/utils').patchEventTargetMethods;
patchEventTargetMethods(XMLHttpRequest.prototype);
require('zone.js/lib/browser/browser');

that means we patch XMLHttpRequest directly before browser is loaded, so when patchEventTargetMethods runs on EventTarget, it works as expected.

That used to work until 0.8.9.

Between 0.8.10 and 0.8.12, that's no longer possible, as zone.js/lib/zone.ts will complain that Promise is already patched:

Error: Zone.js has detected that ZoneAwarePromise `(window|global).Promise` has been overwritten.

Since 0.8.13, patchEventTargetMethods was moved into lib/common/events.ts, so I face importing errors, when executing require('zone.js/lib/zone’) - before my call on patchEventTargetMethods:

node_modules/zone.js/lib/common/events.ts:53:26
    Cannot find name '_global'.

So, as I understand the main purpose of #748 was about making Zone more modular, I guess there might be another way to reach patchEventTargetMethods and call it directly for XMLHttpRequest before I run into that issue. Or maybe importing a couple of modules instead of just relying on dist/zone.js.

Is there any light that could help me solve this issue? Hopefully I’d like to stick to latest Zone versions, so I’m able to upgrade to Angular 5+.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions