Skip to content

Commit

Permalink
feat: reuse existing style elements in dev
Browse files Browse the repository at this point in the history
  • Loading branch information
cyco130 committed Apr 1, 2023
1 parent 15177a1 commit d355e59
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/vite/src/client/client.ts
Expand Up @@ -333,6 +333,13 @@ async function waitForSuccessfulPing(
}

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

// collect existing style tags 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 d355e59

Please sign in to comment.