fix(frontend/copilot): add rootMargin prop to LoadMoreSentinel for bottom pagination

The bottom sentinel (forward pagination) needs rootMargin "0px 0px 200px 0px"
to pre-trigger loading 200px before the user hits the absolute bottom.
The top sentinel (backward pagination) keeps its "200px 0px 0px 0px" default.
This commit is contained in:
Zamil Majdy
2026-04-15 20:19:41 +07:00
parent e85c042eb6
commit 3d3aef58ac

View File

@@ -131,11 +131,16 @@ function LoadMoreSentinel({
isLoading,
messageCount,
onLoadMore,
rootMargin = "200px 0px 0px 0px",
}: {
hasMore: boolean;
isLoading: boolean;
messageCount: number;
onLoadMore: () => void;
/** IntersectionObserver rootMargin. Top sentinel uses "200px 0px 0px 0px"
* (pre-trigger when approaching from above); bottom sentinel should use
* "0px 0px 200px 0px" (pre-trigger when approaching from below). */
rootMargin?: string;
}) {
const sentinelRef = useRef<HTMLDivElement>(null);
const onLoadMoreRef = useRef(onLoadMore);
@@ -170,11 +175,11 @@ function LoadMoreSentinel({
}
onLoadMoreRef.current();
},
{ rootMargin: "200px 0px 0px 0px" },
{ rootMargin },
);
observer.observe(sentinelRef.current);
return () => observer.disconnect();
}, [hasMore, isLoading, scrollRef]);
}, [hasMore, isLoading, rootMargin, scrollRef]);
// After React commits new DOM nodes (prepended messages), adjust
// scrollTop so the user stays at the same visual position.
@@ -453,6 +458,7 @@ export function ChatMessagesContainer({
isLoading={!!isLoadingMore}
messageCount={messages.length}
onLoadMore={onLoadMore}
rootMargin="0px 0px 200px 0px"
/>
)}
</ConversationContent>