Skip to content

Commit 1b18f1a

Browse files
committed
fix(client): put close() back as the member function
1 parent ff9395d commit 1b18f1a

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

packages/vite/src/client/overlay.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ const codeframeRE = /^(?:>?\s+\d+\s+\|.*|\s+\|\s*\^.*)\r?\n/gm
140140
const { HTMLElement = class {} as typeof globalThis.HTMLElement } = globalThis
141141
export class ErrorOverlay extends HTMLElement {
142142
root: ShadowRoot
143+
closeOnEsc: (e: KeyboardEvent) => void
143144

144145
constructor(err: ErrorPayload['err'], links = true) {
145146
super()
@@ -172,22 +173,17 @@ export class ErrorOverlay extends HTMLElement {
172173
e.stopPropagation()
173174
})
174175

175-
const close = () => {
176-
this.parentNode?.removeChild(this)
177-
document.removeEventListener('keydown', closeOnEsc)
178-
}
179-
180176
this.addEventListener('click', () => {
181-
close()
177+
this.close()
182178
})
183179

184-
const closeOnEsc = (e: KeyboardEvent) => {
180+
this.closeOnEsc = (e: KeyboardEvent) => {
185181
if (e.key === 'Escape' || e.code === 'Escape') {
186-
close()
182+
this.close()
187183
}
188184
}
189185

190-
document.addEventListener('keydown', closeOnEsc)
186+
document.addEventListener('keydown', this.closeOnEsc)
191187
}
192188

193189
text(selector: string, text: string, linkFiles = false): void {
@@ -215,6 +211,10 @@ export class ErrorOverlay extends HTMLElement {
215211
}
216212
}
217213
}
214+
close(): void {
215+
this.parentNode?.removeChild(this)
216+
document.removeEventListener('keydown', this.closeOnEsc)
217+
}
218218
}
219219

220220
export const overlayId = 'vite-error-overlay'

0 commit comments

Comments
 (0)