From 61a882b6226f6a6a39862f7eca29ea45dd67867f Mon Sep 17 00:00:00 2001 From: Aditya Hegde Date: Tue, 30 Dec 2025 15:58:46 +0530 Subject: [PATCH 1/2] fix: auto scroll not working for the final assistant message --- web-common/src/features/chat/core/messages/Messages.svelte | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/web-common/src/features/chat/core/messages/Messages.svelte b/web-common/src/features/chat/core/messages/Messages.svelte index d8f711b9c43..412c2cfa257 100644 --- a/web-common/src/features/chat/core/messages/Messages.svelte +++ b/web-common/src/features/chat/core/messages/Messages.svelte @@ -48,6 +48,7 @@ // Track previous block count to detect new content let previousBlockCount = 0; + let previousBlockType = ""; // Check if user is near the bottom of a scroll container function isNearBottom(element: Element, threshold = 100): boolean { @@ -64,8 +65,12 @@ // - Only scroll during streaming if user is near the bottom (respect scroll position) afterUpdate(() => { const currentBlockCount = blocks.length; - const hasNewBlocks = currentBlockCount > previousBlockCount; + const currentBlockType = blocks[currentBlockCount - 1]?.type ?? ""; + const hasNewBlocks = + currentBlockCount > previousBlockCount || + currentBlockType !== previousBlockType; previousBlockCount = currentBlockCount; + previousBlockType = currentBlockType; if (messagesContainer && layout === "sidebar") { if (hasNewBlocks || isNearBottom(messagesContainer)) { From c7035665ff0f0c915309f84c9a03e2639b0d3fb1 Mon Sep 17 00:00:00 2001 From: Aditya Hegde Date: Wed, 14 Jan 2026 08:29:19 +0530 Subject: [PATCH 2/2] tweaks --- .../src/features/chat/core/messages/Messages.svelte | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/web-common/src/features/chat/core/messages/Messages.svelte b/web-common/src/features/chat/core/messages/Messages.svelte index 412c2cfa257..02d76fc282a 100644 --- a/web-common/src/features/chat/core/messages/Messages.svelte +++ b/web-common/src/features/chat/core/messages/Messages.svelte @@ -46,7 +46,8 @@ $: isConversationEmpty = ($getConversationQuery.data?.messages?.length ?? 0) === 0; - // Track previous block count to detect new content + // Track previous block count to detect new content and previous block type to detect block changing. + // This is used to determine whether to scroll to bottom of messages container or not. let previousBlockCount = 0; let previousBlockType = ""; @@ -61,24 +62,24 @@ } // Auto-scroll behavior: - // - Always scroll when new blocks are added (new message sent or response started) + // - Always scroll when new blocks are added or if the last block changes (new message sent or response started) // - Only scroll during streaming if user is near the bottom (respect scroll position) afterUpdate(() => { const currentBlockCount = blocks.length; const currentBlockType = blocks[currentBlockCount - 1]?.type ?? ""; - const hasNewBlocks = + const hasBlockChanged = currentBlockCount > previousBlockCount || currentBlockType !== previousBlockType; previousBlockCount = currentBlockCount; previousBlockType = currentBlockType; if (messagesContainer && layout === "sidebar") { - if (hasNewBlocks || isNearBottom(messagesContainer)) { + if (hasBlockChanged || isNearBottom(messagesContainer)) { scrollToBottom(messagesContainer); } } else if (layout === "fullpage") { const parentWrapper = messagesContainer.closest(".chat-messages-wrapper"); - if (parentWrapper && (hasNewBlocks || isNearBottom(parentWrapper))) { + if (parentWrapper && (hasBlockChanged || isNearBottom(parentWrapper))) { scrollToBottom(parentWrapper); } }