Skip to content

Commit

Permalink
feat: reuse existing style elements in dev (#12678)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyco130 committed Apr 5, 2023
1 parent 3b912fb commit 3a41bd8
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/vite/src/client/client.ts
Expand Up @@ -363,6 +363,13 @@ function waitForWindowShow() {
}

const sheetsMap = new Map<string, HTMLStyleElement>()

// collect existing style elements that may have been inserted during SSR
// to avoid FOUC or duplicate styles
document.querySelectorAll('style[data-vite-dev-id]').forEach((el) => {
sheetsMap.set(el.getAttribute('data-vite-dev-id')!, el as HTMLStyleElement)
})

// all css imports should be inserted at the same position
// because after build it will be a single css file
let lastInsertedStyle: HTMLStyleElement | undefined
Expand Down

0 comments on commit 3a41bd8

Please sign in to comment.