From 1b69b0f3ac5655098c588a4341a4c84a648431af Mon Sep 17 00:00:00 2001 From: MadCcc <1075746765@qq.com> Date: Thu, 3 Aug 2023 20:30:34 +0800 Subject: [PATCH] fix: dom not appended should not be treated as ShadowRoot --- src/Dom/shadow.ts | 2 +- tests/shadow.test.tsx | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Dom/shadow.ts b/src/Dom/shadow.ts index 2aa8b2dc..eaa44451 100644 --- a/src/Dom/shadow.ts +++ b/src/Dom/shadow.ts @@ -6,7 +6,7 @@ function getRoot(ele: Node) { * Check if is in shadowRoot */ export function inShadow(ele: Node) { - return getRoot(ele) !== ele?.ownerDocument; + return getRoot(ele) instanceof ShadowRoot; } /** diff --git a/tests/shadow.test.tsx b/tests/shadow.test.tsx index 3c81ede7..ba4dab3c 100644 --- a/tests/shadow.test.tsx +++ b/tests/shadow.test.tsx @@ -19,5 +19,10 @@ describe('shadow', () => { expect(getShadowRoot(button)).toBeNull(); }); + + it('should return null if dom is not appended', () => { + const button = document.createElement('button'); + expect(getShadowRoot(button)).toBeNull(); + }); }); });