From 0c07764097591bf6ab61f8d040ff5a541b6e62b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Wed, 11 Nov 2026 22:20:43 +0100 Subject: [PATCH] refactor(settings): drop two query keys nothing reads The unit-system and glucose-unit selects invalidated `userUnitPreference()` and `userGlucoseUnit()` after a save, but no query was ever registered under either key; every surface reads the units from the account payload, which both selects already refresh. --- .../baselines/version-stamp-comments.json | 4 ++-- src/components/settings/glucose-unit-select.tsx | 9 +++------ .../settings/unit-preference-select.tsx | 8 ++------ src/lib/query-keys/auth.ts | 17 ----------------- 4 files changed, 7 insertions(+), 31 deletions(-) diff --git a/src/__tests__/baselines/version-stamp-comments.json b/src/__tests__/baselines/version-stamp-comments.json index 95b72ddd6..e93abac30 100644 --- a/src/__tests__/baselines/version-stamp-comments.json +++ b/src/__tests__/baselines/version-stamp-comments.json @@ -1,7 +1,7 @@ { "$comment": "Comment lines that open with a release version, per file under src/. Maintained by src/__tests__/version-stamp-ratchet.test.ts.", "count": 2881, - "total": 9185, + "total": 9184, "entries": { "__tests__/account-payload-consumer-guard.test.ts": 2, "__tests__/acting-account-boundary-guard.test.ts": 7, @@ -2691,7 +2691,7 @@ "lib/queries/use-profile-claim.ts": 4, "lib/query-keys/admin.ts": 12, "lib/query-keys/ai-runs.ts": 1, - "lib/query-keys/auth.ts": 9, + "lib/query-keys/auth.ts": 8, "lib/query-keys/coach.ts": 13, "lib/query-keys/custom-metrics.ts": 1, "lib/query-keys/cycle.ts": 1, diff --git a/src/components/settings/glucose-unit-select.tsx b/src/components/settings/glucose-unit-select.tsx index 496e0322c..234ec0434 100644 --- a/src/components/settings/glucose-unit-select.tsx +++ b/src/components/settings/glucose-unit-select.tsx @@ -29,9 +29,9 @@ import { resolveGlucoseUnit, type GlucoseUnit } from "@/lib/glucose"; * locale. * * Persistence mirrors the unit-system select: a change PATCHes - * `/api/auth/me/glucose-unit` immediately and invalidates `queryKeys.authMe()` - * plus `queryKeys.userGlucoseUnit()`, so the dashboard tiles, the glucose - * insight page and the targets panel re-render on the next /me refetch. + * `/api/auth/me/glucose-unit` immediately and invalidates `queryKeys.authMe()`, + * so the dashboard tiles and the glucose insight page re-render on the next + * /me refetch. */ export function GlucoseUnitSelect({ isAuthenticated, @@ -66,9 +66,6 @@ export function GlucoseUnitSelect({ onSuccess: () => { toastWrittenOutcome("success", t("settings.dashboard.glucoseUnit.saved")); queryClient.invalidateQueries({ queryKey: queryKeys.authMe() }); - queryClient.invalidateQueries({ - queryKey: queryKeys.userGlucoseUnit(), - }); setOptimistic(null); }, onError: (err) => { diff --git a/src/components/settings/unit-preference-select.tsx b/src/components/settings/unit-preference-select.tsx index 0ba6d4712..b8baf5b9c 100644 --- a/src/components/settings/unit-preference-select.tsx +++ b/src/components/settings/unit-preference-select.tsx @@ -23,9 +23,8 @@ type UnitPreference = "metric" | "imperial"; * picker rather than in a standalone card (it replaces the retired * ``). Persistence is unchanged: a change PATCHes * `/api/auth/me/unit-preference` immediately and invalidates - * `queryKeys.authMe()` + `queryKeys.userUnitPreference()` so every chart - * display transform (km/h vs mph, km vs mi) re-renders on the next /me - * refetch — no manual reload, no contract change. + * `queryKeys.authMe()`, the account payload every chart display transform + * (km/h vs mph, km vs mi) reads, so they re-render on the next /me refetch. */ export function UnitPreferenceSelect({ isAuthenticated, @@ -59,9 +58,6 @@ export function UnitPreferenceSelect({ onSuccess: () => { toastWrittenOutcome("success", t("settings.dashboard.units.saved")); queryClient.invalidateQueries({ queryKey: queryKeys.authMe() }); - queryClient.invalidateQueries({ - queryKey: queryKeys.userUnitPreference(), - }); setOptimistic(null); }, onError: (err) => { diff --git a/src/lib/query-keys/auth.ts b/src/lib/query-keys/auth.ts index f5753c7b2..89c3fe0a4 100644 --- a/src/lib/query-keys/auth.ts +++ b/src/lib/query-keys/auth.ts @@ -23,23 +23,6 @@ export const authKeys = { * settings/ai-section, targets/target-edit-sheet). */ userThresholds: () => ["user", "thresholds"] as const, - /** - * v1.7.0 — Settings → Display metric/imperial control reads its - * current value from `GET /api/auth/me/unit-preference`. The PATCH - * mutation also invalidates `authMe()` so `useAuth().unitPreference` - * (and every chart display transform that keys off it) re-renders - * without a manual reload. - */ - userUnitPreference: () => ["user", "unit-preference"] as const, - /** - * The mg/dL vs mmol/L glucose display control behind - * `GET /api/auth/me/glucose-unit`. A separate axis from the - * metric/imperial preference above — metric countries are split on - * which one they read glucose in — so it carries its own key. The - * PATCH also invalidates `authMe()`, since every glucose surface - * resolves the unit from the account payload rather than from here. - */ - userGlucoseUnit: () => ["user", "glucose-unit"] as const, passkeys: () => ["passkeys"] as const,