From 5397b78f5453715c41f1685ab515cf93e0bcad7f Mon Sep 17 00:00:00 2001 From: zerosrat Date: Mon, 29 May 2023 16:30:39 +0800 Subject: [PATCH 1/2] fix: addEventListenerWrap param target may be nullish --- src/Dom/addEventListener.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Dom/addEventListener.js b/src/Dom/addEventListener.js index eacf3d07..4e94d78e 100644 --- a/src/Dom/addEventListener.js +++ b/src/Dom/addEventListener.js @@ -7,12 +7,12 @@ export default function addEventListenerWrap(target, eventType, cb, option) { ReactDOM.unstable_batchedUpdates(cb, e); } : cb; - if (target.addEventListener) { + if (target?.addEventListener) { target.addEventListener(eventType, callback, option); } return { remove: () => { - if (target.removeEventListener) { + if (target?.removeEventListener) { target.removeEventListener(eventType, callback, option); } }, From 903dfe1c23c09fc41aa2fe5de0a3812fa35a8236 Mon Sep 17 00:00:00 2001 From: zerosrat Date: Wed, 26 Jul 2023 10:24:31 +0800 Subject: [PATCH 2/2] fix: add nullish in dynamicCSS.ts --- src/Dom/dynamicCSS.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Dom/dynamicCSS.ts b/src/Dom/dynamicCSS.ts index ed2d8973..1a6b3ede 100644 --- a/src/Dom/dynamicCSS.ts +++ b/src/Dom/dynamicCSS.ts @@ -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[]; } @@ -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 @@ -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); }