From 19a24a516032fe31b939e21cbd8ede09f273bb17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Fri, 12 Jun 2026 21:47:47 +0200 Subject: [PATCH] fix(dashboard): a dose taken on the dashboard updates the dashboard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The hero band, dose tally, verdict and checklist all read one snapshot query that neither refetches on mount nor on focus — and no mutation ever invalidated its key, so a dose taken right there stayed visibly due for up to the next two-minute poll. The snapshot key joins the medication-dependent invalidation bundle; the intake routes already hard-evict the server-side bucket, so the triggered refetch returns post-write data immediately. (#316) --- src/lib/__tests__/query-keys.test.ts | 9 +++++++++ src/lib/query-keys/index.ts | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/src/lib/__tests__/query-keys.test.ts b/src/lib/__tests__/query-keys.test.ts index 1e56d87d3..5b1e70f5f 100644 --- a/src/lib/__tests__/query-keys.test.ts +++ b/src/lib/__tests__/query-keys.test.ts @@ -250,6 +250,15 @@ describe("dependent-key bundles", () => { const keyStrings = medicationDependentKeys.map((k) => JSON.stringify(k)); expect(keyStrings).toContain(JSON.stringify(["compliance-chart-inline"])); }); + + // v1.16.11 — the dashboard snapshot feeds the hero band, dose tally, + // verdict and checklist from ONE query with refetch-on-mount/focus + // off and a 120 s poll. Without this key in the bundle a dose taken + // from the dashboard stayed visibly due until the next poll (#316). + it("medicationDependentKeys bundles the dashboard snapshot (v1.16.11)", () => { + const keyStrings = medicationDependentKeys.map((k) => JSON.stringify(k)); + expect(keyStrings).toContain(JSON.stringify(["dashboard", "snapshot"])); + }); }); /** diff --git a/src/lib/query-keys/index.ts b/src/lib/query-keys/index.ts index c91b1a386..e98e8d0a5 100644 --- a/src/lib/query-keys/index.ts +++ b/src/lib/query-keys/index.ts @@ -103,6 +103,14 @@ export const moodDependentKeys = [ * `queryKeys.medicationDetail(id)` rides under the * `["medications"]` prefix already so a single medication invalidation * also evicts its detail-page read. + * + * v1.16.11 — `dashboardSnapshot` joins the bundle. The hero band, dose + * tally, verdict and checklist all read ONE snapshot query configured + * with refetchOnMount/WindowFocus off and a 120 s poll; without the key + * here a dose taken from the dashboard stayed visibly due for up to two + * minutes. The intake routes already hard-evict the server-side + * snapshot bucket, so the refetch this triggers returns post-write data + * immediately. */ export const medicationDependentKeys = [ queryKeys.medications(), @@ -110,6 +118,7 @@ export const medicationDependentKeys = [ queryKeys.insightsRoot(), queryKeys.insightsTargets(), queryKeys.gamificationAchievements(), + queryKeys.dashboardSnapshot(), ["dashboard-medication-compliance"] as const, ["compliance-chart-inline"] as const, ];