perf(web): pause hidden live polling

This commit is contained in:
lingniu
2026-07-16 08:35:37 +08:00
parent e06778e38c
commit 4c54cfa6ff
9 changed files with 46 additions and 15 deletions

View File

@@ -4,6 +4,14 @@ export const QUERY_MEMORY = {
summaryGcTime: 60_000
} as const;
// Live views must not spend traffic while the browser tab is hidden, but they
// should reconcile immediately when an operator returns instead of waiting for
// the next interval tick.
export const LIVE_QUERY_POLICY = {
refetchIntervalInBackground: false,
refetchOnWindowFocus: true
} as const;
export function retainPreviousPageWithinScope<T>(scope: string, scopeIndex = 1) {
return (previous: T | undefined, previousQuery?: { queryKey: readonly unknown[] }) => previousQuery?.queryKey[scopeIndex] === scope ? previous : undefined;
}