Skip to content

Commit 3a41bd8

Browse files
authoredApr 5, 2023
feat: reuse existing style elements in dev (#12678)
1 parent 3b912fb commit 3a41bd8

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed
 

‎packages/vite/src/client/client.ts

+7
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,13 @@ function waitForWindowShow() {
363363
}
364364

365365
const sheetsMap = new Map<string, HTMLStyleElement>()
366+
367+
// collect existing style elements that may have been inserted during SSR
368+
// to avoid FOUC or duplicate styles
369+
document.querySelectorAll('style[data-vite-dev-id]').forEach((el) => {
370+
sheetsMap.set(el.getAttribute('data-vite-dev-id')!, el as HTMLStyleElement)
371+
})
372+
366373
// all css imports should be inserted at the same position
367374
// because after build it will be a single css file
368375
let lastInsertedStyle: HTMLStyleElement | undefined

0 commit comments

Comments
 (0)
Please sign in to comment.