From 07b79de20355112b4c21a1f13c68aa5ec5e39a1f Mon Sep 17 00:00:00 2001 From: lostb1t Date: Sat, 30 May 2026 09:11:59 +0200 Subject: [PATCH] fix: Do not cache background request for mediasources (#1602) --- .../items/page.tsx | 6 ++++-- app/_layout.tsx | 5 +++-- hooks/useItemQuery.ts | 7 +++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/(auth)/(tabs)/(home,libraries,search,favorites,watchlists)/items/page.tsx b/app/(auth)/(tabs)/(home,libraries,search,favorites,watchlists)/items/page.tsx index d61072177..b62761791 100644 --- a/app/(auth)/(tabs)/(home,libraries,search,favorites,watchlists)/items/page.tsx +++ b/app/(auth)/(tabs)/(home,libraries,search,favorites,watchlists)/items/page.tsx @@ -30,8 +30,10 @@ const Page: React.FC = () => { ItemFields.MediaStreams, ]); - // Lazily preload item with full media sources in background - const { data: itemWithSources } = useItemQuery(id, isOffline, undefined, []); + // Lazily preload item with full media sources in background — never cache + const { data: itemWithSources } = useItemQuery(id, isOffline, undefined, [], { + gcTime: 0, + }); const opacity = useSharedValue(1); const animatedStyle = useAnimatedStyle(() => { diff --git a/app/_layout.tsx b/app/_layout.tsx index 79278b702..dd7d9e964 100644 --- a/app/_layout.tsx +++ b/app/_layout.tsx @@ -375,8 +375,9 @@ function Layout() { maxAge: 1000 * 60 * 60 * 24, // 24 hours max cache age dehydrateOptions: { shouldDehydrateQuery: (query) => { - // Only persist successful queries - return query.state.status === "success"; + return ( + query.state.status === "success" && query.options.gcTime !== 0 + ); }, }, }} diff --git a/hooks/useItemQuery.ts b/hooks/useItemQuery.ts index 370b5f35a..d7616b8cc 100644 --- a/hooks/useItemQuery.ts +++ b/hooks/useItemQuery.ts @@ -12,11 +12,17 @@ export const excludeFields = (fieldsToExclude: ItemFields[]) => { ); }; +type ExtraQueryOptions = { + gcTime?: number; + staleTime?: number; +}; + export const useItemQuery = ( itemId: string | undefined, isOffline?: boolean, fields?: ItemFields[], excludeFields?: ItemFields[], + queryOptions?: ExtraQueryOptions, ) => { const [api] = useAtom(apiAtom); const [user] = useAtom(userAtom); @@ -53,5 +59,6 @@ export const useItemQuery = ( refetchOnWindowFocus: true, refetchOnReconnect: true, networkMode: "always", + ...queryOptions, }); };