MCPcopy
hub / github.com/vitejs/vite / updateStyle

Function updateStyle

packages/vite/src/client/client.ts:555–584  ·  view source on GitHub ↗
(id: string, content: string)

Source from the content-addressed store, hash-verified

553let lastInsertedStyle: HTMLStyleElement | undefined
554
555export function updateStyle(id: string, content: string): void {
556 if (linkSheetsMap.has(id)) return
557
558 let style = sheetsMap.get(id)
559 if (!style) {
560 style = document.createElement('style')
561 style.setAttribute('type', 'text/css')
562 style.setAttribute('data-vite-dev-id', id)
563 style.textContent = content
564 if (cspNonce) {
565 style.setAttribute('nonce', cspNonce)
566 }
567
568 if (!lastInsertedStyle) {
569 document.head.appendChild(style)
570
571 // reset lastInsertedStyle after async
572 // because dynamically imported css will be split into a different file
573 setTimeout(() => {
574 lastInsertedStyle = undefined
575 }, 0)
576 } else {
577 lastInsertedStyle.insertAdjacentElement('afterend', style)
578 }
579 lastInsertedStyle = style
580 } else {
581 style.textContent = content
582 }
583 sheetsMap.set(id, style)
584}
585
586export function removeStyle(id: string): void {
587 if (linkSheetsMap.has(id)) {

Callers

nothing calls this directly

Calls 3

hasMethod · 0.80
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected