diff --git a/src/lib/queries/__tests__/use-dashboard-snapshot.test.tsx b/src/lib/queries/__tests__/use-dashboard-snapshot.test.tsx index 9205493a0..c19d91a69 100644 --- a/src/lib/queries/__tests__/use-dashboard-snapshot.test.tsx +++ b/src/lib/queries/__tests__/use-dashboard-snapshot.test.tsx @@ -83,7 +83,13 @@ describe("useDashboardSnapshot — auto-refresh on an open page", () => { useDashboardSnapshot(); const opts = lastOpts(); expect(opts.staleTime).toBe(60_000); - expect(opts.refetchOnMount).toBe(false); + const refetchOnMount = opts.refetchOnMount as (query: { + state: { isInvalidated: boolean }; + }) => boolean; + // A live cell is read as it is on remount ... + expect(refetchOnMount({ state: { isInvalidated: false } })).toBe(false); + // ... and one restored from the offline copy (invalidated) fetches. + expect(refetchOnMount({ state: { isInvalidated: true } })).toBe(true); }); it("always refetches on focus so freshness is not suppressed by staleTime", () => { diff --git a/src/lib/queries/use-dashboard-snapshot.ts b/src/lib/queries/use-dashboard-snapshot.ts index 9218ec6c3..280564b75 100644 --- a/src/lib/queries/use-dashboard-snapshot.ts +++ b/src/lib/queries/use-dashboard-snapshot.ts @@ -215,7 +215,13 @@ export function useDashboardSnapshot(enabled = true) { queryFn: makeSnapshotQueryFn(queryClient), enabled, staleTime: 60_000, - refetchOnMount: false, + // A remount of a cell that holds live data reads it as it is, but a cell + // restored from the offline copy (`restorePersistedQueryCache`) arrives + // invalidated and must fetch on its first mount. Plain `false` kept the + // restored copy on screen: a page reloaded right after a write, before + // the persister had flushed the newer snapshot, painted the pre-write + // dashboard until the two-minute poll. + refetchOnMount: (query) => query.state.isInvalidated, // Keep the snapshot and Today digest in lockstep after a background sync. // Both are out-of-band reads, so staleTime cannot signal that a worker // landed a new arrival while the browser was hidden.