From 9808dd3033db1717b03983fa2285dce1c6aa1ba9 Mon Sep 17 00:00:00 2001 From: gosangam Date: Sun, 14 Jun 2026 00:35:45 +0530 Subject: [PATCH] fix: fix feed component --- components/feed/home-feed.tsx | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/components/feed/home-feed.tsx b/components/feed/home-feed.tsx index 54785582..d278a432 100644 --- a/components/feed/home-feed.tsx +++ b/components/feed/home-feed.tsx @@ -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,