Reset the <main> scroll on forward navigation

This commit is contained in:
dtonon 2026-06-04 16:53:54 +01:00
parent 2b1a6257de
commit 7cd9a68ae3

View file

@ -12,6 +12,7 @@
import DeleteModal from "$lib/components/DeleteModal.svelte";
import Toast from "$lib/components/Toast.svelte";
import { page } from "$app/state";
import { afterNavigate } from "$app/navigation";
import { onMount } from "svelte";
import { auth, restoreSession } from "$lib/auth.svelte";
import { loadGroup } from "$lib/group.svelte";
@ -29,6 +30,15 @@
const mode = MODE;
const chatEnabled = true;
// The main column is its own scroll container (overflow-y-auto) and persists
// across navigations, so SvelteKit's window-only scroll restoration never
// resets it. Scroll it back to top on forward navigation; leave back/forward
// (popstate) alone so returning to a listing keeps its place.
let mainEl = $state<HTMLElement | null>(null);
afterNavigate((nav) => {
if (nav.type !== "popstate") mainEl?.scrollTo(0, 0);
});
onMount(async () => {
loadResources();
loadPartials();
@ -111,6 +121,7 @@
>
<LeftSidebar {mode} {activeRoom} {activeResource} {contactsActive} />
<main
bind:this={mainEl}
class="no-scrollbar md:min-h-0 md:overflow-y-auto {showDiscussions
? 'md:flex-[3]'
: 'md:flex-1'}