Skip to content

Commit a18a9f9

Browse files
authored
Merge 903dfe1 into 43394c4
2 parents 43394c4 + 903dfe1 commit a18a9f9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/Dom/dynamicCSS.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function getOrder(prepend?: Prepend): AppendType {
4646
*/
4747
function findStyles(container: ContainerType) {
4848
return Array.from(
49-
(containerCache.get(container) || container).children,
49+
(containerCache.get(container) || container)?.children ?? [],
5050
).filter(node => node.tagName === 'STYLE') as HTMLStyleElement[];
5151
}
5252

@@ -66,7 +66,7 @@ export function injectCSS(css: string, option: Options = {}) {
6666
styleNode.innerHTML = css;
6767

6868
const container = getContainer(option);
69-
const { firstChild } = container;
69+
const firstChild = container?.firstChild;
7070

7171
if (prepend) {
7272
// If is queue `prepend`, it will prepend first style and then append rest style
@@ -85,7 +85,9 @@ export function injectCSS(css: string, option: Options = {}) {
8585
}
8686

8787
// Use `insertBefore` as `prepend`
88-
container.insertBefore(styleNode, firstChild);
88+
if (firstChild) {
89+
container.insertBefore(styleNode, firstChild);
90+
}
8991
} else {
9092
container.appendChild(styleNode);
9193
}

0 commit comments

Comments
 (0)