Skip to content

Commit

Permalink
fix: fix error overlay stack
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Apr 10, 2024
1 parent f8e0791 commit 5f0e6a3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
5 changes: 1 addition & 4 deletions packages/vite/src/client/overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ kbd {
`

// Error Template
let template: HTMLElement
const createTemplate = () =>
h(
'div',
Expand Down Expand Up @@ -214,9 +213,7 @@ export class ErrorOverlay extends HTMLElement {
constructor(err: ErrorPayload['err'], links = true) {
super()
this.root = this.attachShadow({ mode: 'open' })

template ??= createTemplate()
this.root.appendChild(template)
this.root.appendChild(createTemplate())

codeframeRE.lastIndex = 0
const hasFrame = err.frame && codeframeRE.test(err.frame)
Expand Down
23 changes: 23 additions & 0 deletions playground/html/__tests__/html.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,29 @@ describe.runIf(isServe)('invalid', () => {
const content = await page.waitForSelector('text=Good HTML')
expect(content).toBeTruthy()
})

test('stack', async () => {
await page.goto(viteTestUrl + '/invalid.html')

const errorOverlay = await page.waitForSelector('vite-error-overlay')
const hiddenPromise = errorOverlay.waitForElementState('hidden')
await page.keyboard.press('Escape')
await hiddenPromise

viteServer.hot.send({
type: 'error',
err: {
message: 'someError',
stack: [
'Error: someError',
' at someMethod (/some/file.ts:1:2)',
].join('\n'),
},
})
const newErrorOverlay = await page.waitForSelector('vite-error-overlay')
const stack = await newErrorOverlay.$$eval('.stack', (m) => m[0].innerHTML)
expect(stack).toMatch(/^Error: someError/)
})
})

describe('Valid HTML', () => {
Expand Down

0 comments on commit 5f0e6a3

Please sign in to comment.