Skip to content

Commit

Permalink
fix(client): put close() back as the member function
Browse files Browse the repository at this point in the history
  • Loading branch information
chaejunlee committed Jul 12, 2023
1 parent ff9395d commit 1b18f1a
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions packages/vite/src/client/overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ const codeframeRE = /^(?:>?\s+\d+\s+\|.*|\s+\|\s*\^.*)\r?\n/gm
const { HTMLElement = class {} as typeof globalThis.HTMLElement } = globalThis
export class ErrorOverlay extends HTMLElement {
root: ShadowRoot
closeOnEsc: (e: KeyboardEvent) => void

constructor(err: ErrorPayload['err'], links = true) {
super()
Expand Down Expand Up @@ -172,22 +173,17 @@ export class ErrorOverlay extends HTMLElement {
e.stopPropagation()
})

const close = () => {
this.parentNode?.removeChild(this)
document.removeEventListener('keydown', closeOnEsc)
}

this.addEventListener('click', () => {
close()
this.close()
})

const closeOnEsc = (e: KeyboardEvent) => {
this.closeOnEsc = (e: KeyboardEvent) => {
if (e.key === 'Escape' || e.code === 'Escape') {
close()
this.close()
}
}

document.addEventListener('keydown', closeOnEsc)
document.addEventListener('keydown', this.closeOnEsc)
}

text(selector: string, text: string, linkFiles = false): void {
Expand Down Expand Up @@ -215,6 +211,10 @@ export class ErrorOverlay extends HTMLElement {
}
}
}
close(): void {
this.parentNode?.removeChild(this)
document.removeEventListener('keydown', this.closeOnEsc)
}
}

export const overlayId = 'vite-error-overlay'
Expand Down

0 comments on commit 1b18f1a

Please sign in to comment.