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],