From c029f01212f4ce68df7f3ce887cd8f753bcd4a54 Mon Sep 17 00:00:00 2001 From: Andreas Ohlsson Date: Thu, 8 Oct 2026 12:34:30 +0200 Subject: [PATCH] fix: don't re-observe a detached element after destroy() A position update queued with lowPriority() before destroy() can run after it. updatePos() then calls observePosition() on the detached element and creates a new IntersectionObserver rooted at document.documentElement, which keeps the detached subtree alive for the rest of the session. Fixes #246 --- src/index.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/index.ts b/src/index.ts index 772b21f7..f2adf264 100644 --- a/src/index.ts +++ b/src/index.ts @@ -145,6 +145,10 @@ function isOffscreen(el: Element): boolean { function observePosition(el: Element) { const oldObserver = intersections.get(el) oldObserver?.disconnect() + if (!el.isConnected) { + intersections.delete(el) + return + } let rect = coords.get(el) let invocations = 0 const buffer = 5