Pause TanStack interval refetches when the tab is hidden (D8)
Set refetchIntervalInBackground: false as a QueryClient default so all interval-based polls (widgets ~30s, message-queue 5s, media build progress 1s) pause when document.visibilityState === 'hidden'. Battery-friendly on mobile -- the dashboard is the page most likely to be left open on a phone. The media build-progress poll previously forced refetchIntervalInBackground: true; that override is removed so it inherits the default. The build keeps running server-side; the poll resumes and catches up when the user returns to the tab. 122 tests pass; lint/build green. Refs openspec/changes/mobile-responsive-parity/verify-report.md residual risk #3 (D8 battery follow-up).
This commit is contained in:
+10
-1
@@ -62,7 +62,16 @@ import {
|
||||
} from "lucide-react";
|
||||
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: { queries: { retry: 1, refetchOnWindowFocus: false } },
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
retry: 1,
|
||||
refetchOnWindowFocus: false,
|
||||
// Pause interval-based refetches (widgets ~30s, queue status 5s,
|
||||
// media build progress 1s) when the tab is hidden. Saves battery on
|
||||
// mobile (D8 follow-up). Build progress polls resume on return.
|
||||
refetchIntervalInBackground: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
function useDarkMode() {
|
||||
|
||||
@@ -14,7 +14,10 @@ export function useMediaStatus(jellyfinServiceId?: string) {
|
||||
staleTime: 5_000,
|
||||
refetchInterval: (query) =>
|
||||
query.state.data?.build_running ? 1000 : false,
|
||||
refetchIntervalInBackground: true,
|
||||
// Inherit the default refetchIntervalInBackground: false — pause the
|
||||
// 1s build-progress poll when the tab is hidden. The build keeps
|
||||
// running server-side; the poll resumes and catches up on return.
|
||||
// Battery-friendly (D8 follow-up).
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user