Skip to content

Commit 70f1bc6

Browse files
authored
feat: enhance style injection logic to support custom root elements (#5027)
1 parent fe0f766 commit 70f1bc6

File tree

1 file changed

+8
-1
lines changed
  • packages-integrations/runtime/src

1 file changed

+8
-1
lines changed

packages-integrations/runtime/src/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,14 @@ export default async function init(inlineConfig: RuntimeOptions = {}): Promise<v
164164

165165
runtimeOptions.configResolved?.(userConfig, userConfigDefaults)
166166
const uno = await createGenerator(userConfig, userConfigDefaults)
167-
const inject = (styleElement: HTMLStyleElement) => runtimeOptions.inject ? runtimeOptions.inject(styleElement) : html().prepend(styleElement)
167+
const inject = (styleElement: HTMLStyleElement) => {
168+
const rootElement = inlineConfig.rootElement?.()
169+
if (rootElement) {
170+
rootElement.appendChild(styleElement)
171+
return
172+
}
173+
runtimeOptions.inject ? runtimeOptions.inject(styleElement) : html().prepend(styleElement)
174+
}
168175
const rootElement = () => runtimeOptions.rootElement ? runtimeOptions.rootElement() : defaultDocument.body
169176
const styleElements = new Map<string, HTMLStyleElement>()
170177

0 commit comments

Comments
 (0)