fix: Do not cache background request for mediasources (#1602)

This commit is contained in:
lostb1t
2026-05-30 09:11:59 +02:00
committed by GitHub
parent cf91c4c682
commit 07b79de203
3 changed files with 14 additions and 4 deletions

View File

@@ -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(() => {

View File

@@ -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
);
},
},
}}

View File

@@ -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,
});
};