fix: fix feed component

This commit is contained in:
gosangam
2026-06-14 00:35:45 +05:30
parent b248f962a1
commit 9808dd3033
+20 -4
View File
@@ -63,14 +63,30 @@ export function HomeFeed() {
}
}, []);
// Initial page + measure where the list sits in the document (so the window
// virtualiser offsets correctly below the streak component).
useEffect(() => {
void loadPage();
}, [loadPage]);
// The window virtualiser needs `scrollMargin` = how far down the document the
// list begins, to map window scroll → which items are visible. `.offsetTop`
// is relative to the offsetParent (wrong inside the page layout), so measure
// the document-absolute top (rect.top + scrollY — scroll-invariant). The
// streak component above loads async and changes height, so re-measure on
// resize and on any body reflow.
useEffect(() => {
if (parentRef.current) setOffsetTop(parentRef.current.offsetTop);
}, [loading]);
const measure = () => {
const el = parentRef.current;
if (el) setOffsetTop(el.getBoundingClientRect().top + window.scrollY);
};
measure();
window.addEventListener("resize", measure);
const ro = new ResizeObserver(measure);
ro.observe(document.body);
return () => {
window.removeEventListener("resize", measure);
ro.disconnect();
};
}, []);
const virtualizer = useWindowVirtualizer({
count: items.length,