Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/vite/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ async function handleMessage(payload: HMRPayload) {
window.location.reload()
return
} else {
clearErrorOverlay()
if (enableOverlay) {
clearErrorOverlay()
}
isFirstUpdate = false
}
await Promise.all(
Expand Down
73 changes: 39 additions & 34 deletions packages/vite/src/client/overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,39 +165,42 @@ kbd {
`

// Error Template
const template = h(
'div',
{ class: 'backdrop', part: 'backdrop' },
h(
'div',
{ class: 'window', part: 'window' },
h(
'pre',
{ class: 'message', part: 'message' },
h('span', { class: 'plugin', part: 'plugin' }),
h('span', { class: 'message-body', part: 'message-body' }),
),
h('pre', { class: 'file', part: 'file' }),
h('pre', { class: 'frame', part: 'frame' }),
h('pre', { class: 'stack', part: 'stack' }),
h(
'div',
{ class: 'tip', part: 'tip' },
'Click outside, press ',
h('kbd', {}, 'Esc'),
' key, or fix the code to dismiss.',
h('br'),
'You can also disable this overlay by setting ',
h('code', { part: 'config-option-name' }, 'server.hmr.overlay'),
' to ',
h('code', { part: 'config-option-value' }, 'false'),
' in ',
h('code', { part: 'config-file-name' }, hmrConfigName),
'.',
),
),
h('style', {}, templateStyle),
)
const template =
'document' in globalThis
? h(
'div',
{ class: 'backdrop', part: 'backdrop' },
h(
'div',
{ class: 'window', part: 'window' },
h(
'pre',
{ class: 'message', part: 'message' },
h('span', { class: 'plugin', part: 'plugin' }),
h('span', { class: 'message-body', part: 'message-body' }),
),
h('pre', { class: 'file', part: 'file' }),
h('pre', { class: 'frame', part: 'frame' }),
h('pre', { class: 'stack', part: 'stack' }),
h(
'div',
{ class: 'tip', part: 'tip' },
'Click outside, press ',
h('kbd', {}, 'Esc'),
' key, or fix the code to dismiss.',
h('br'),
'You can also disable this overlay by setting ',
h('code', { part: 'config-option-name' }, 'server.hmr.overlay'),
' to ',
h('code', { part: 'config-option-value' }, 'false'),
' in ',
h('code', { part: 'config-file-name' }, hmrConfigName),
'.',
),
),
h('style', {}, templateStyle),
)
: undefined

const fileRE = /(?:[a-zA-Z]:\\|\/).*?:\d+:\d+/g
const codeframeRE = /^(?:>?\s*\d+\s+\|.*|\s+\|\s*\^.*)\r?\n/gm
Expand All @@ -213,7 +216,9 @@ export class ErrorOverlay extends HTMLElement {
super()
this.root = this.attachShadow({ mode: 'open' })

this.root.appendChild(template)
if (template) {
this.root.appendChild(template)
}

codeframeRE.lastIndex = 0
const hasFrame = err.frame && codeframeRE.test(err.frame)
Expand Down
2 changes: 1 addition & 1 deletion playground/worker/__tests__/es/worker-es.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ test('emit chunk', async () => {
)
await untilUpdated(
() => page.textContent('.emit-chunk-dynamic-import-worker'),
'"A string/es/"',
'"A stringmodule1/es/"',
true,
)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ test.runIf(isBuild)('emit chunk', async () => {
)
await untilUpdated(
() => page.textContent('.emit-chunk-dynamic-import-worker'),
'"A string./"',
'"A stringmodule1./"',
true,
)
})
Expand Down
6 changes: 5 additions & 1 deletion playground/worker/emit-chunk-dynamic-import-worker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import module1Url from './modules/module1.js?url'

import('./modules/module0').then((module) => {
self.postMessage(module.default + import.meta.env.BASE_URL)
import(/* @vite-ignore */ module1Url).then((module1) => {
self.postMessage(module.default + module1.msg1 + import.meta.env.BASE_URL)
})
})

// for sourcemap
Expand Down