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(() => {
|
useEffect(() => {
|
||||||
void loadPage();
|
void loadPage();
|
||||||
}, [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(() => {
|
useEffect(() => {
|
||||||
if (parentRef.current) setOffsetTop(parentRef.current.offsetTop);
|
const measure = () => {
|
||||||
}, [loading]);
|
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({
|
const virtualizer = useWindowVirtualizer({
|
||||||
count: items.length,
|
count: items.length,
|
||||||
|
|||||||
Reference in New Issue
Block a user