Skip to content
Closed
Changes from all 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
17 changes: 13 additions & 4 deletions packages/vite/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,18 +281,27 @@ function notifyListeners(event: string, data: any): void {
}

const enableOverlay = __HMR_ENABLE_OVERLAY__
const hasDocument = typeof document !== 'undefined'

function createErrorOverlay(err: ErrorPayload['err']) {
clearErrorOverlay()
document.body.appendChild(new ErrorOverlay(err))
if (hasDocument) {
document.body.appendChild(new ErrorOverlay(err))
}
}

function clearErrorOverlay() {
document.querySelectorAll<ErrorOverlay>(overlayId).forEach((n) => n.close())
if (hasDocument) {
document.querySelectorAll<ErrorOverlay>(overlayId).forEach((n) => n.close())
}
}

function hasErrorOverlay() {
return document.querySelectorAll(overlayId).length
if (hasDocument) {
return document.querySelectorAll(overlayId).length
}

return false
}

let pending = false
Expand Down Expand Up @@ -378,7 +387,7 @@ const sheetsMap = new Map<string, HTMLStyleElement>()

// collect existing style elements that may have been inserted during SSR
// to avoid FOUC or duplicate styles
if ('document' in globalThis) {
if (hasDocument) {
document
.querySelectorAll<HTMLStyleElement>('style[data-vite-dev-id]')
.forEach((el) => {
Expand Down