diff --git a/src/utils.ts b/src/utils.ts index 2c056ec..27fa2f9 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -20,9 +20,10 @@ export function findSocket(socketsCache: WeakMap, elements: */ export function elementsFromPoint(x: number, y: number, root: ShadowRoot | Document = document) { const elements = root.elementsFromPoint(x, y) + const shadowRoot = elements[0]?.shadowRoot - if (elements[0]?.shadowRoot) { - elements.unshift(...elementsFromPoint(x, y, elements[0].shadowRoot)) + if (shadowRoot && shadowRoot !== root) { + elements.unshift(...elementsFromPoint(x, y, shadowRoot)) } return elements