From 8f048f94e0e00c445bdd668cbd5c8f3ae2bbe9a2 Mon Sep 17 00:00:00 2001 From: Simon Cordt Date: Thu, 25 Sep 2025 12:11:15 +0200 Subject: [PATCH] Improve intersection observer root detection --- web/js/pqueue.ui.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/web/js/pqueue.ui.js b/web/js/pqueue.ui.js index 67cc61d..5ddbdbd 100644 --- a/web/js/pqueue.ui.js +++ b/web/js/pqueue.ui.js @@ -1066,12 +1066,20 @@ state.historyPaging.hasMore = true; } + const scroller = UI.getScrollContainer(); + const rootIsAncestor = (el, ancestor) => { + try { + if (!ancestor || !(ancestor instanceof Element)) return false; + return ancestor.contains(el); + } catch (err) { return false; } + }; + const root = rootIsAncestor(sentinel, scroller) ? scroller : null; const obs = new IntersectionObserver((entries) => { entries.forEach((entry) => { if (!entry.isIntersecting) return; Events.loadMoreHistory(); }); - }, { root: null, rootMargin: '600px 0px', threshold: 0 }); + }, { root: root, rootMargin: '600px 0px', threshold: 0 }); obs.observe(sentinel); state.historyObserver = obs; } catch (err) { /* noop */ }