Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix accumulated stacks in error overlay #16393

Merged
merged 4 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 1 addition & 4 deletions packages/vite/src/client/overlay.ts
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
Expand Up @@ -274,6 +274,29 @@ describe.runIf(isServe)('invalid', () => {
expect(isVisbleOverlay).toBeFalsy()
})

test('stack', async () => {
sapphi-red marked this conversation as resolved.
Show resolved Hide resolved
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/)
})

test('should reload when fixed', async () => {
await page.goto(viteTestUrl + '/invalid.html')
await editFile('invalid.html', (content) => {
Expand Down