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
This commit is contained in:
Classic298 2026-10-20 23:53:38 +02:00 • committed by GitHub
parent 2bebbb44e1
commit c4153a6eea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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;