From c4153a6eeaeb6a0c5ec8cc152a1bdf328b848859 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Tue, 20 Oct 2026 23:53:38 +0200 Subject: [PATCH] fix: shared chat pages keep reloading and jump back to the bottom (#32725) Since 0.12.3, any chat opened under /s/, whether through a share link or by an admin viewing another user's chat, was fetched again and again from the moment it opened, and each fetch scrolled the page to the bottom. Scrolling up was impossible and older messages never loaded. The chat is now loaded once when the page opens. Fixes #32657 --- src/routes/s/[id]/+page.svelte | 37 ++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/routes/s/[id]/+page.svelte b/src/routes/s/[id]/+page.svelte index 032c78e728..40f7c4ea86 100644 --- a/src/routes/s/[id]/+page.svelte +++ b/src/routes/s/[id]/+page.svelte @@ -48,30 +48,33 @@ $sessionUser && ($sessionUser.role === 'admin' || ($sessionUser.permissions?.chat?.import ?? true)); + // Reading history here would rerun this on every history change. $: if ($page.params.id) { - (async () => { - if (await loadSharedChat()) { - loaded = true; - await tick(); - const target = $page.url.searchParams.get('message'); - if (target && history.messages[target]) { - autoScroll = false; - history.currentId = getDeepestChildId(history, target); - await tick(); - await messagesComponent?.scrollToMessage(target); - } else messagesComponent?.scrollToBottom(); - } else if (localStorage.token) { - await goto('/'); - } else { - await goto(`/auth?redirect=${encodeURIComponent($page.url.pathname)}`); - } - })(); + loadAndScroll(); } ////////////////////////// // Web functions ////////////////////////// + const loadAndScroll = async () => { + if (await loadSharedChat()) { + loaded = true; + await tick(); + const target = $page.url.searchParams.get('message'); + if (target && history.messages[target]) { + autoScroll = false; + history.currentId = getDeepestChildId(history, target); + await tick(); + await messagesComponent?.scrollToMessage(target); + } else messagesComponent?.scrollToBottom(); + } else if (localStorage.token) { + await goto('/'); + } else { + await goto(`/auth?redirect=${encodeURIComponent($page.url.pathname)}`); + } + }; + const loadSharedChat = async () => { const token = localStorage.token ?? ''; const shareId = $page.params.id;