fix: refresh libraries on drawer open and stop playlist page render loop
Continuous Integration / build_web (push) Failing after 0s
Continuous Integration / build (macos-latest) (push) Skipped
Continuous Integration / build (ubuntu-22.04) (push) Skipped
Continuous Integration / build (windows-11-arm) (push) Skipped
Continuous Integration / build (windows-latest) (push) Skipped
Continuous Integration / nightly_release (push) Skipped
Continuous Integration / build_web (push) Failing after 0s
Continuous Integration / build (macos-latest) (push) Skipped
Continuous Integration / build (ubuntu-22.04) (push) Skipped
Continuous Integration / build (windows-11-arm) (push) Skipped
Continuous Integration / build (windows-latest) (push) Skipped
Continuous Integration / nightly_release (push) Skipped
- 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.
This commit is contained in:
1 parent
b00f93d262
commit
cc1391bb7d
2 files changed
+13
-6
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
import { getUserViewApi } from "@jellyfin/sdk/lib/utils/api/user-view-api";
|
import { getUserViewApi } from "@jellyfin/sdk/lib/utils/api/user-view-api";
|
||||||
import { Divider, Drawer, List, ListItem, ListItemButton } from "@mui/material";
|
import { Divider, Drawer, List, ListItem, ListItemButton } from "@mui/material";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import React, { useMemo } from "react";
|
import React, { useEffect, useMemo } from "react";
|
||||||
import { useApiInContext } from "@/utils/store/api";
|
import { useApiInContext } from "@/utils/store/api";
|
||||||
import { useCentralStore } from "@/utils/store/central";
|
import { useCentralStore } from "@/utils/store/central";
|
||||||
import ListItemLink from "../listItemLink";
|
import ListItemLink from "../listItemLink";
|
||||||
@@ -14,7 +14,7 @@ interface NavigationDrawerProps {
|
|||||||
|
|
||||||
export const NavigationDrawer = ({ open, onClose }: NavigationDrawerProps) => {
|
export const NavigationDrawer = ({ open, onClose }: NavigationDrawerProps) => {
|
||||||
const api = useApiInContext((s) => s.api);
|
const api = useApiInContext((s) => s.api);
|
||||||
const [user] = useCentralStore((s) => [s.currentUser]);
|
const user = useCentralStore((s) => s.currentUser);
|
||||||
|
|
||||||
const libraries = useQuery({
|
const libraries = useQuery({
|
||||||
queryKey: ["libraries"],
|
queryKey: ["libraries"],
|
||||||
@@ -31,6 +31,13 @@ export const NavigationDrawer = ({ open, onClose }: NavigationDrawerProps) => {
|
|||||||
networkMode: "always",
|
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(() => {
|
const drawerPaperProps = useMemo(() => {
|
||||||
return {
|
return {
|
||||||
className: "glass library-drawer",
|
className: "glass library-drawer",
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ function PlaylistTitlePage() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const musicTracks = useQuery({
|
const musicTracks = useQuery({
|
||||||
queryKey: ["item", "musicTracks"],
|
queryKey: ["item", id, "musicTracks"],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
if (!api) return null;
|
if (!api) return null;
|
||||||
if (!item.data?.Id) return null;
|
if (!item.data?.Id) return null;
|
||||||
@@ -84,13 +84,13 @@ function PlaylistTitlePage() {
|
|||||||
networkMode: "always",
|
networkMode: "always",
|
||||||
});
|
});
|
||||||
|
|
||||||
const [setAppBackdrop] = useBackdropStore((state) => [state.setBackdrop]);
|
const setAppBackdrop = useBackdropStore((state) => state.setBackdrop);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (item.isSuccess) {
|
if (item.isSuccess) {
|
||||||
setAppBackdrop("", "");
|
setAppBackdrop(undefined);
|
||||||
}
|
}
|
||||||
}, []);
|
}, [item.isSuccess, setAppBackdrop]);
|
||||||
|
|
||||||
if (item.isPending || similarItems.isPending) {
|
if (item.isPending || similarItems.isPending) {
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in new issue
Block a user