From ea157c9aa8ed5abe10b85baf23233b3058647adb Mon Sep 17 00:00:00 2001 From: Bohdan Triapitsyn Date: Fri, 24 Jul 2026 20:59:02 +0300 Subject: [PATCH] fix: force auto scroll behavior in virtualized message list navigation Removed smooth scroll option to prevent offset issues on unmount Ensured consistent auto-reconciliation for variable-height rows during scroll --- packages/ui/src/components/chat/MessageList.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/ui/src/components/chat/MessageList.tsx b/packages/ui/src/components/chat/MessageList.tsx index 2ce4442e..8a76a0e3 100644 --- a/packages/ui/src/components/chat/MessageList.tsx +++ b/packages/ui/src/components/chat/MessageList.tsx @@ -1587,7 +1587,7 @@ const MessageList = React.forwardRef(({ return container.querySelector(`[data-message-id="${messageId}"]`); }, [resolveScrollContainer]); - const scrollHistoryIndexIntoView = React.useCallback((index: number, behavior: ScrollBehavior = 'auto') => { + const scrollHistoryIndexIntoView = React.useCallback((index: number) => { if (index < 0 || index >= historyEntries.length) { return false; } @@ -1601,7 +1601,11 @@ const MessageList = React.forwardRef(({ return false; } - virtualizer.scrollToIndex(index, { align: 'start', behavior: behavior === 'smooth' ? 'smooth' : 'auto' }); + // Smooth scrolling can stop at a stale offset while unmounted, + // variable-height rows replace estimates with real measurements. Use + // exact auto-reconciliation; mounted targets still take the smooth DOM + // path below. + virtualizer.scrollToIndex(index, { align: 'start', behavior: 'auto' }); return true; }, [historyEntries.length, shouldVirtualizeHistory]); @@ -1651,7 +1655,7 @@ const MessageList = React.forwardRef(({ return false; } - return scrollHistoryIndexIntoView(index, behavior); + return scrollHistoryIndexIntoView(index); }, scrollToMessageId: (messageId: string, options?: { behavior?: ScrollBehavior }) => { @@ -1665,7 +1669,7 @@ const MessageList = React.forwardRef(({ || ( trailingStreamingEntry !== undefined && index >= historyEntries.length ? false - : scrollHistoryIndexIntoView(index, behavior) + : scrollHistoryIndexIntoView(index) ); }, @@ -1774,7 +1778,7 @@ const MessageList = React.forwardRef(({ if (!applyAnchor()) { const index = messageIndexMap.get(anchor.messageId); if (typeof index === 'number' && index < historyEntries.length) { - return scrollHistoryIndexIntoView(index, 'auto'); + return scrollHistoryIndexIntoView(index); } }