From a31aea640582b30a316dc2d32f39aa7063e88690 Mon Sep 17 00:00:00 2001 From: Owen Buckley Date: Mon, 19 Feb 2024 17:10:51 -0500 Subject: [PATCH] re-use existing DOM shim globals if they exist --- src/dom-shim.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/dom-shim.js b/src/dom-shim.js index 39579fc..6131aa4 100644 --- a/src/dom-shim.js +++ b/src/dom-shim.js @@ -137,7 +137,8 @@ class CustomElementsRegistry { // mock top level aliases (globalThis === window) // https://developer.mozilla.org/en-US/docs/Web/API/Window -globalThis.addEventListener = noop; -globalThis.document = new Document(); -globalThis.customElements = new CustomElementsRegistry(); -globalThis.HTMLElement = HTMLElement; \ No newline at end of file +// make this "idempotent" for now until a better idea comes along - https://github.com/ProjectEvergreen/wcc/discussions/145 +globalThis.addEventListener = globalThis.addEventListener ?? noop; +globalThis.document = globalThis.document ?? new Document(); +globalThis.customElements = globalThis.customElements ?? new CustomElementsRegistry(); +globalThis.HTMLElement = globalThis.HTMLElement ?? HTMLElement; \ No newline at end of file