From fc5f3995737978fe574eb50cd547a4310bb141d0 Mon Sep 17 00:00:00 2001 From: Algorithm5838 <108630393+Algorithm5838@users.noreply.github.com> Date: Sat, 28 Feb 2026 22:13:48 +0300 Subject: [PATCH] perf: batch scrollToBottom during streaming via rAF (#21946) --- src/lib/components/chat/Chat.svelte | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 52a7aa925..42a509583 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -1281,6 +1281,16 @@ }); } }; + + let scrollRAF = null; + const scheduleScrollToBottom = () => { + if (!scrollRAF) { + scrollRAF = requestAnimationFrame(async () => { + scrollRAF = null; + await scrollToBottom(); + }); + } + }; const chatCompletedHandler = async (_chatId, modelId, responseMessageId, messages) => { const res = await chatCompleted(localStorage.token, { model: modelId, @@ -1698,7 +1708,7 @@ await tick(); if (autoScroll) { - scrollToBottom(); + scheduleScrollToBottom(); } }; @@ -2482,7 +2492,7 @@ } if (autoScroll) { - scrollToBottom(); + scheduleScrollToBottom(); } }