From ad72dc6658bca7f1244a5876736720299dc21399 Mon Sep 17 00:00:00 2001 From: G30 <50341825+silentoplayz@users.noreply.github.com> Date: Mon, 17 Aug 2026 02:40:14 -0400 Subject: [PATCH] fix: scroll to the top of a chat on the first click of Scroll to Top (#28659) --- src/lib/components/chat/Messages.svelte | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/lib/components/chat/Messages.svelte b/src/lib/components/chat/Messages.svelte index 301aa93c6b..7c6c4f08c7 100644 --- a/src/lib/components/chat/Messages.svelte +++ b/src/lib/components/chat/Messages.svelte @@ -159,12 +159,17 @@ messagesCount = null; buildMessages(); await tick(); - if (messages.length > 0) { - const firstMessageEl = document.getElementById(`message-${messages[0].id}`); - if (firstMessageEl) { - firstMessageEl.scrollIntoView({ behavior: 'smooth', block: 'start' }); - } - } + + const element = getMessagesContainer(); + if (!element) return; + + element.scrollTo({ top: 0, behavior: 'smooth' }); + requestAnimationFrame(() => { + element.scrollTo({ top: 0, behavior: 'smooth' }); + requestAnimationFrame(() => { + element.scrollTo({ top: 0, behavior: 'smooth' }); + }); + }); }; const updateChat = async () => {