Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit f5cbb5e

Browse files
committed
fix(inject-css-global.ts):Fixed to be able to write both global and root
1 parent c327e97 commit f5cbb5e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/_internal/utils/inject-css-global.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ const isServer = !isWindowDefined || !isDocumentDefined;
44
let styleElement: HTMLStyleElement;
55

66
function createStyleElement(scoped: string) {
7+
const existingStyleElement = document.querySelector(`[data-scope="${scoped}"]`);
8+
if (existingStyleElement) {
9+
existingStyleElement.remove();
10+
}
11+
712
const styleElement = document.createElement('style');
813
styleElement.setAttribute('data-scope', scoped);
914
styleElement.setAttribute('type', 'text/css');
@@ -15,7 +20,7 @@ function createStyleElement(scoped: string) {
1520
export function injectCSSGlobal(sheet: string, scoped: string) {
1621
if (isInDevelopment) console.log('💫 ' + scoped + ' executing ...' + sheet);
1722
if (isServer) return;
18-
if (styleElement == undefined) styleElement = createStyleElement(scoped);
1923

24+
styleElement = createStyleElement(scoped);
2025
styleElement.textContent = sheet;
2126
}

0 commit comments

Comments
 (0)