fix: fix feed component
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user