fix(platform-server): Do not delete global Event (#53659)

This commit removes a hack that deletes `Event` from the global context
when using domino. Instead, it sets the global event to domino's
implementation of `Event`.

PR Close #53659
This commit is contained in:
Andrew Scott 2023-12-20 10:19:47 -08:00
parent 36318dbd41
commit f4bd5a33d2
2 changed files with 2 additions and 12 deletions

View file

@ -18,15 +18,10 @@ if (typeof window == 'undefined') {
DominoAdapter.makeCurrent();
(global as any).document = getDOM().getDefaultDocument();
// Trick to avoid Event patching from
// https://github.com/angular/angular/blob/7cf5e95ac9f0f2648beebf0d5bd9056b79946970/packages/platform-browser/src/dom/events/dom_events.ts#L112-L132
// It fails with Domino with TypeError: Cannot assign to read only property
// 'stopImmediatePropagation' of object '#<Event>'
(global as any).Event = null;
// For animation tests, see
// https://github.com/angular/angular/blob/main/packages/animations/browser/src/render/shared.ts#L140
(global as any).Element = domino.impl.Element;
(global as any).isBrowser = false;
(global as any).isNode = true;
(global as any).Event = domino.impl.Event;
}

View file

@ -130,7 +130,6 @@ async function loadDominoOrNull():
/**
* Ensure that global has `Document` if we are in node.js
* @publicApi
*/
export async function ensureDocument(): Promise<void> {
if ((global as any).isBrowser) {
@ -147,11 +146,7 @@ export async function ensureDocument(): Promise<void> {
savedDocument = (global as any).document;
(global as any).window = window;
(global as any).document = window.document;
// Trick to avoid Event patching from
// https://github.com/angular/angular/blob/7cf5e95ac9f0f2648beebf0d5bd9056b79946970/packages/platform-browser/src/dom/events/dom_events.ts#L112-L132
// It fails with Domino with TypeError: Cannot assign to read only property
// 'stopImmediatePropagation' of object '#<Event>'
(global as any).Event = null;
(global as any).Event = domino.impl.Event;
savedNode = (global as any).Node;
// Domino types do not type `impl`, but it's a documented field.
// See: https://www.npmjs.com/package/domino#usage.