From d430981caa8bd77c9b9c9ea8482c47f16e5d75c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Thu, 12 Nov 2026 15:12:07 +0100 Subject: [PATCH] fix(workouts): refresh the Insights Workouts pill after a workout write The tab strip shows the Workouts pill from the presence read, which stays fresh for five minutes and was not part of the workout write's invalidation. After the first manual workout, or after deleting the last one, the pill stayed missing or stayed on for up to five minutes. --- .../__tests__/record-write-day-keys.test.ts | 15 +++++++++++++++ src/lib/query-keys/index.ts | 4 +++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/lib/query-keys/__tests__/record-write-day-keys.test.ts b/src/lib/query-keys/__tests__/record-write-day-keys.test.ts index 64f54253a..4d9133d52 100644 --- a/src/lib/query-keys/__tests__/record-write-day-keys.test.ts +++ b/src/lib/query-keys/__tests__/record-write-day-keys.test.ts @@ -11,6 +11,7 @@ import { describe, expect, it } from "vitest"; import { invalidateSymptomReads } from "@/components/symptoms/use-symptoms"; import { allergyDependentKeys, + invalidateKeys, cycleDependentKeys, documentDependentKeys, encounterDependentKeys, @@ -47,6 +48,20 @@ describe("record writes reach the day view and the timeline", () => { }, ); + it("a workout write marks the Insights presence read stale", async () => { + // The Workouts pill appears with the first workout and goes with the + // last; the presence read otherwise stays fresh for five minutes. + const client = new QueryClient(); + client.setQueryData(queryKeys.insightsPresence(), { hasWorkouts: false }); + + await invalidateKeys(client, workoutDependentKeys); + + expect( + client.getQueryState(queryKeys.insightsPresence())?.isInvalidated, + ).toBe(true); + client.clear(); + }); + it("a symptom write marks an open day and the timeline stale", async () => { const client = new QueryClient(); const day = queryKeys.day("2026-11-10"); diff --git a/src/lib/query-keys/index.ts b/src/lib/query-keys/index.ts index 57e244539..25b6195f0 100644 --- a/src/lib/query-keys/index.ts +++ b/src/lib/query-keys/index.ts @@ -364,10 +364,12 @@ export const vaccinationDependentKeys = [ * digest names a workout that just arrived and the write evicts the server's * daily caches, so the daily reads ride along; pair call sites with * `refetchInactiveDailyReads`, because both are unmounted wherever the form - * opens outside the dashboard. + * opens outside the dashboard. The Insights tab strip shows the Workouts + * pill from the presence read. */ export const workoutDependentKeys = [ queryKeys.workouts(), + queryKeys.insightsPresence(), queryKeys.dashboardSnapshot(), queryKeys.dailyDigest(), queryKeys.dayRoot(),