Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/Dom/dynamicCSS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function getOrder(prepend?: Prepend): AppendType {
*/
function findStyles(container: ContainerType) {
return Array.from(
(containerCache.get(container) || container).children,
(containerCache.get(container) || container)?.children ?? [],
).filter(node => node.tagName === 'STYLE') as HTMLStyleElement[];
}

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

const container = getContainer(option);
const { firstChild } = container;
const firstChild = container?.firstChild;

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

// Use `insertBefore` as `prepend`
container.insertBefore(styleNode, firstChild);
if (firstChild) {
container.insertBefore(styleNode, firstChild);
}
} else {
container.appendChild(styleNode);
}
Expand Down