Improve intersection observer root detection

This commit is contained in:
Simon Cordt
2025-09-25 12:11:15 +02:00
parent a26102deb5
commit 8f048f94e0
+9 -1
View File
@@ -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 */ }