From 380ad39ad401673f736412f0268c5109232a5188 Mon Sep 17 00:00:00 2001 From: npeter83 Date: Mon, 15 Jun 2026 22:19:05 +0200 Subject: [PATCH] fix(playlists): don't drop the restored selection during initial load The auto-select effect ran while the playlist query was still loading (empty list), nulling the localStorage-restored selection so F5 fell back to the first playlist. Wait for the first load (listQuery.data) before adjusting the selection. --- frontend/src/components/Playlists.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/Playlists.tsx b/frontend/src/components/Playlists.tsx index 6ccf771..f0b77eb 100644 --- a/frontend/src/components/Playlists.tsx +++ b/frontend/src/components/Playlists.tsx @@ -229,6 +229,9 @@ export default function Playlists({ canWrite }: { canWrite: boolean }) { // Keep the selection valid: default to the first playlist, and if the selected one // disappears (e.g. just deleted) drop to the next available, or clear when none remain. useEffect(() => { + // Wait for the first load before adjusting the selection — otherwise the empty + // placeholder list would null the restored selection and we'd fall back to the first. + if (!listQuery.data) return; if (!playlists.length) { if (selectedId != null) setSelectedId(null); return; @@ -236,7 +239,7 @@ export default function Playlists({ canWrite }: { canWrite: boolean }) { if (selectedId == null || !playlists.some((p) => p.id === selectedId)) { setSelectedId(playlists[0].id); } - }, [playlists, selectedId]); + }, [playlists, selectedId, listQuery.data]); const detailQuery = useQuery({ queryKey: ["playlist", selectedId],