From cc1391bb7dbc9d9cd39783fe0fef275b6cc7981c Mon Sep 17 00:00:00 2001 From: 1xDed Date: Fri, 27 Nov 2026 11:57:49 +0300 Subject: [PATCH] fix: refresh libraries on drawer open and stop playlist page render loop - Zustand selector returned a new array on every render in PlaylistTitlePage, causing getSnapshot/useSyncExternalStore infinite updates. - Cache playlist tracks per playlist id. - Refetch server views each time the drawer opens so newly added libraries (e.g. Music) appear without restarting the app. --- src/components/appBar/navigationDrawer.tsx | 11 +++++++++-- src/routes/_api/music/playlist/$id.tsx | 8 ++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/components/appBar/navigationDrawer.tsx b/src/components/appBar/navigationDrawer.tsx index 0db9212..ee33a01 100644 --- a/src/components/appBar/navigationDrawer.tsx +++ b/src/components/appBar/navigationDrawer.tsx @@ -1,7 +1,7 @@ import { getUserViewApi } from "@jellyfin/sdk/lib/utils/api/user-view-api"; import { Divider, Drawer, List, ListItem, ListItemButton } from "@mui/material"; import { useQuery } from "@tanstack/react-query"; -import React, { useMemo } from "react"; +import React, { useEffect, useMemo } from "react"; import { useApiInContext } from "@/utils/store/api"; import { useCentralStore } from "@/utils/store/central"; import ListItemLink from "../listItemLink"; @@ -14,7 +14,7 @@ interface NavigationDrawerProps { export const NavigationDrawer = ({ open, onClose }: NavigationDrawerProps) => { const api = useApiInContext((s) => s.api); - const [user] = useCentralStore((s) => [s.currentUser]); + const user = useCentralStore((s) => s.currentUser); const libraries = useQuery({ queryKey: ["libraries"], @@ -31,6 +31,13 @@ export const NavigationDrawer = ({ open, onClose }: NavigationDrawerProps) => { networkMode: "always", }); + // Libraries can be added on the server while the app is running; refresh + // the view list every time the drawer opens so they show up without restart. + const refetchLibraries = libraries.refetch; + useEffect(() => { + if (open) refetchLibraries(); + }, [open, refetchLibraries]); + const drawerPaperProps = useMemo(() => { return { className: "glass library-drawer", diff --git a/src/routes/_api/music/playlist/$id.tsx b/src/routes/_api/music/playlist/$id.tsx index 0ca2f39..c2ca025 100644 --- a/src/routes/_api/music/playlist/$id.tsx +++ b/src/routes/_api/music/playlist/$id.tsx @@ -70,7 +70,7 @@ function PlaylistTitlePage() { }); const musicTracks = useQuery({ - queryKey: ["item", "musicTracks"], + queryKey: ["item", id, "musicTracks"], queryFn: async () => { if (!api) return null; if (!item.data?.Id) return null; @@ -84,13 +84,13 @@ function PlaylistTitlePage() { networkMode: "always", }); - const [setAppBackdrop] = useBackdropStore((state) => [state.setBackdrop]); + const setAppBackdrop = useBackdropStore((state) => state.setBackdrop); useEffect(() => { if (item.isSuccess) { - setAppBackdrop("", ""); + setAppBackdrop(undefined); } - }, []); + }, [item.isSuccess, setAppBackdrop]); if (item.isPending || similarItems.isPending) { return (