revert: restore stable chat history scrolling
This commit is contained in:
@@ -1372,8 +1372,6 @@ const MessageList = React.forwardRef<MessageListHandle, MessageListProps>(({
|
|||||||
scrollEl.scrollTop += prependedHeight;
|
scrollEl.scrollTop += prependedHeight;
|
||||||
});
|
});
|
||||||
|
|
||||||
const [historyVirtualRows, setHistoryVirtualRows] = React.useState<VirtualItem[]>(EMPTY_VIRTUAL_ROWS);
|
|
||||||
|
|
||||||
const historyVirtualizer = useVirtualizer({
|
const historyVirtualizer = useVirtualizer({
|
||||||
count: historyEntries.length,
|
count: historyEntries.length,
|
||||||
getScrollElement: resolveScrollContainer,
|
getScrollElement: resolveScrollContainer,
|
||||||
@@ -1383,9 +1381,6 @@ const MessageList = React.forwardRef<MessageListHandle, MessageListProps>(({
|
|||||||
useAnimationFrameWithResizeObserver: true,
|
useAnimationFrameWithResizeObserver: true,
|
||||||
overscan: MESSAGE_LIST_OVERSCAN,
|
overscan: MESSAGE_LIST_OVERSCAN,
|
||||||
enabled: shouldVirtualizeHistory,
|
enabled: shouldVirtualizeHistory,
|
||||||
onChange: () => {
|
|
||||||
setHistoryVirtualRows(historyVirtualizer.getVirtualItems());
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
React.useLayoutEffect(() => {
|
React.useLayoutEffect(() => {
|
||||||
@@ -1440,13 +1435,10 @@ const MessageList = React.forwardRef<MessageListHandle, MessageListProps>(({
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Sync virtual rows on initial mount and when virtualization toggles.
|
const historyVirtualRows = React.useMemo(
|
||||||
// Ongoing updates are handled by the virtualizer's onChange callback.
|
() => (shouldVirtualizeHistory ? historyVirtualizer.getVirtualItems() : EMPTY_VIRTUAL_ROWS),
|
||||||
React.useLayoutEffect(() => {
|
[historyVirtualizer, shouldVirtualizeHistory],
|
||||||
setHistoryVirtualRows(
|
);
|
||||||
shouldVirtualizeHistory ? historyVirtualizer.getVirtualItems() : EMPTY_VIRTUAL_ROWS,
|
|
||||||
);
|
|
||||||
}, [shouldVirtualizeHistory, historyVirtualizer]);
|
|
||||||
|
|
||||||
const allEntries = React.useMemo(() => {
|
const allEntries = React.useMemo(() => {
|
||||||
return trailingStreamingEntry ? [...historyEntries, trailingStreamingEntry] : historyEntries;
|
return trailingStreamingEntry ? [...historyEntries, trailingStreamingEntry] : historyEntries;
|
||||||
|
|||||||
@@ -411,9 +411,7 @@ export const useChatAutoFollow = ({
|
|||||||
}, [sessionIsWorking, startFollowLoop]);
|
}, [sessionIsWorking, startFollowLoop]);
|
||||||
|
|
||||||
// Replay a deferred restoreSnapshot once ChatViewport mounts.
|
// Replay a deferred restoreSnapshot once ChatViewport mounts.
|
||||||
// useLayoutEffect ensures scroll position is set before the browser paints,
|
React.useEffect(() => {
|
||||||
// preventing a visible flash of content at the wrong scroll position.
|
|
||||||
React.useLayoutEffect(() => {
|
|
||||||
if (!containerEl) return;
|
if (!containerEl) return;
|
||||||
if (pendingInitialRestoreRef.current && pendingInitialRestoreRef.current === currentSessionId) {
|
if (pendingInitialRestoreRef.current && pendingInitialRestoreRef.current === currentSessionId) {
|
||||||
void restoreSnapshot();
|
void restoreSnapshot();
|
||||||
|
|||||||
Reference in New Issue
Block a user