Fix scroll restoration for virtualized containers

This commit is contained in:
AdamArstall committed 2026-03-28 09:35:40 +00:00
1 parent 1c51eac578
commit 46943be4e1
8 files changed
+41

No files matched your search

@@ -2,6 +2,7 @@
import { onMount, onDestroy } from 'svelte';
import { Disc3 } from 'lucide-svelte';
import AlbumCard from './AlbumCard.svelte';
import { restoreScrollOnBackForward } from '$lib/utils/scrollRestore';
// Types
interface LocalAlbum {
@@ -229,6 +230,8 @@
});
resizeObserver.observe(containerEl);
}
restoreScrollOnBackForward(containerEl, (v) => scrollTop = v);
});
onDestroy(() => {
@@ -1,6 +1,7 @@
<script lang="ts">
import { onMount, onDestroy } from 'svelte';
import { Mic2, Upload } from 'lucide-svelte';
import { restoreScrollOnBackForward } from '$lib/utils/scrollRestore';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type Artist = any;
@@ -183,6 +184,8 @@
});
resizeObserver.observe(containerEl);
}
restoreScrollOnBackForward(containerEl, (v) => scrollTop = v);
});
onDestroy(() => {
@@ -1,6 +1,7 @@
<script lang="ts">
import { onMount, onDestroy } from 'svelte';
import { Mic2 } from 'lucide-svelte';
import { restoreScrollOnBackForward } from '$lib/utils/scrollRestore';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type Artist = any;
@@ -162,6 +163,8 @@
});
resizeObserver.observe(containerEl);
}
restoreScrollOnBackForward(containerEl, (v) => scrollTop = v);
});
onDestroy(() => {
@@ -4,6 +4,7 @@
import { Disc3, Loader2 } from 'lucide-svelte';
import AlbumCard from './AlbumCard.svelte';
import QualityBadge from './QualityBadge.svelte';
import { restoreScrollOnBackForward } from '$lib/utils/scrollRestore';
interface FavoriteAlbum {
id: string;
@@ -256,6 +257,8 @@
});
resizeObserver.observe(containerEl);
}
restoreScrollOnBackForward(containerEl, (v) => scrollTop = v);
});
onDestroy(() => {
@@ -3,6 +3,7 @@
import { t } from '$lib/i18n';
import { Mic2 } from 'lucide-svelte';
import { cachedSrc } from '$lib/actions/cachedImage';
import { restoreScrollOnBackForward } from '$lib/utils/scrollRestore';
interface FavoriteArtist {
id: number;
@@ -191,6 +192,8 @@
});
resizeObserver.observe(containerEl);
}
restoreScrollOnBackForward(containerEl, (v) => scrollTop = v);
});
// Observe header sentinel for scroll-past detection
@@ -3,6 +3,7 @@
import { t } from '$lib/i18n';
import { Mic2 } from 'lucide-svelte';
import { cachedSrc } from '$lib/actions/cachedImage';
import { restoreScrollOnBackForward } from '$lib/utils/scrollRestore';
interface FavoriteArtist {
id: number;
@@ -193,6 +194,8 @@
});
resizeObserver.observe(containerEl);
}
restoreScrollOnBackForward(containerEl, (v) => scrollTop = v);
});
onDestroy(() => {
@@ -3,6 +3,7 @@
import TrackRow from './TrackRow.svelte';
import type { OfflineCacheStatus } from '$lib/stores/offlineCacheState';
import { isBlacklisted as isArtistBlacklisted } from '$lib/stores/artistBlacklistStore';
import { restoreScrollOnBackForward } from '$lib/utils/scrollRestore';
// Use generic types to match whatever caller passes
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -284,6 +285,8 @@
});
resizeObserver.observe(containerEl);
}
restoreScrollOnBackForward(containerEl, (v) => scrollTop = v);
});
onDestroy(() => {
+20
View File
@@ -0,0 +1,20 @@
import { tick } from 'svelte';
import { getNavigationState, getSavedScrollPosition } from '../stores/navigationStore';
export function restoreScrollOnBackForward(
containerEl: HTMLElement | null,
setScrollTop?: (value: number) => void
) {
const navState = getNavigationState();
if (navState.isBackForward) {
const saved = getSavedScrollPosition(navState.activeView, navState.activeItemId);
setScrollTop?.(saved);
tick().then(() => {
if (containerEl) {
containerEl.scrollTop = saved;
}
});
}
}