From a52b45ea3d1b0f37effa100a571a7bf267e7c2d6 Mon Sep 17 00:00:00 2001 From: Lucas Garron Date: Fri, 15 Jul 2022 06:42:50 -0700 Subject: [PATCH] fix: avoid errors when loading the overlay code in workers (#9064) --- packages/vite/src/client/overlay.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/vite/src/client/overlay.ts b/packages/vite/src/client/overlay.ts index 150c570fbc8aaf..6a43434b7f320c 100644 --- a/packages/vite/src/client/overlay.ts +++ b/packages/vite/src/client/overlay.ts @@ -115,6 +115,9 @@ code { const fileRE = /(?:[a-zA-Z]:\\|\/).*?:\d+:\d+/g const codeframeRE = /^(?:>?\s+\d+\s+\|.*|\s+\|\s*\^.*)\r?\n/gm +// Allow `ErrorOverlay` to extend `HTMLElement` even in environments where +// `HTMLElement` was not originally defined. +const { HTMLElement = class {} } = globalThis export class ErrorOverlay extends HTMLElement { root: ShadowRoot @@ -184,6 +187,7 @@ export class ErrorOverlay extends HTMLElement { } export const overlayId = 'vite-error-overlay' +const { customElements } = globalThis // Ensure `customElements` is defined before the next line. if (customElements && !customElements.get(overlayId)) { customElements.define(overlayId, ErrorOverlay) }