Skip to content

Commit 08c1452

Browse files
authored
fix: undefined document in worker (#12988)
1 parent bd86375 commit 08c1452

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/vite/src/client/client.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,11 @@ const sheetsMap = new Map<string, HTMLStyleElement>()
365365

366366
// collect existing style elements that may have been inserted during SSR
367367
// to avoid FOUC or duplicate styles
368-
document.querySelectorAll('style[data-vite-dev-id]').forEach((el) => {
369-
sheetsMap.set(el.getAttribute('data-vite-dev-id')!, el as HTMLStyleElement)
370-
})
368+
if ('document' in globalThis) {
369+
document.querySelectorAll('style[data-vite-dev-id]').forEach((el) => {
370+
sheetsMap.set(el.getAttribute('data-vite-dev-id')!, el as HTMLStyleElement)
371+
})
372+
}
371373

372374
// all css imports should be inserted at the same position
373375
// because after build it will be a single css file

0 commit comments

Comments
 (0)