mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 08:12:52 +00:00
chore(release): v1.32.19 — clear the Today view the instant a write lands
A dose logged from another screen marked the Today hero and the dashboard stale without re-reading them, so returning to the home page kept showing the old state until the 120 s poll or a hard reload. The daily reads run with refetchOnMount off, so a bundle invalidation with the default active refetch-type never touched them while they were unmounted. Route every intake-affecting medication write through one blessed invalidateMedicationReads (bundle invalidation plus a forced inactive refetch of the digest and snapshot): Take all due, the intake edit dialog, the history bulk/row delete, the dose-history ledger and its add dialog, the lifecycle and danger-zone actions, and the intake import. Give the Vorsorge reminder mutations the same daily-rail refresh, bust the biomarker assessment and the labs-changes read after a lab write, and refetch the daily reads after a briefing regenerate so the Today lead updates without a reload. Restore the dashboard-layout concurrency belt: the settings layout query now always loads its own tokened copy, so a home-page visit can no longer strand a save without its base token and silently drop the v1.32.16 conflict guard. Add a structural guard that fails CI when a new site invalidates a daily-reads bundle without the paired inactive refetch, so this class cannot recur a fourth time, plus behavioural coverage for the batch take and the Vorsorge refresh. Refs #581
This commit is contained in:
1 parent
5c36a9a776
commit
15b8df11bc
22 files changed
+487
-85
No files matched your search
@@ -14,7 +14,7 @@ import type {
|
||||
DailyBriefing as DailyBriefingPayload,
|
||||
TrendAnnotations,
|
||||
} from "@/lib/ai/schema";
|
||||
import { queryKeys } from "@/lib/query-keys";
|
||||
import { queryKeys, refetchInactiveDailyReads } from "@/lib/query-keys";
|
||||
import { apiFetchRaw } from "@/lib/api/api-fetch";
|
||||
import type { BriefingFailureClass } from "@/lib/insights/briefing-failure-marker";
|
||||
|
||||
@@ -381,15 +381,19 @@ export function useInsightsAdvisorQuery(
|
||||
// their query subtree so the per-section text below the advisor card
|
||||
// re-fetches.
|
||||
queryClient.invalidateQueries({ queryKey: queryKeys.insightsRoot() });
|
||||
// v1.18.10 — the dashboard hero surfaces the briefing headline from the
|
||||
// SNAPSHOT (server-lifted `User.insightsCachedText`), not from this
|
||||
// advisor cache. A regenerate rewrites that server cache, so invalidate
|
||||
// the snapshot too — otherwise returning to the Startseite shows the
|
||||
// previous briefing under the greeting until the snapshot's own stale
|
||||
// window lapses. Closes "the briefing doesn't update" on the dashboard.
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: queryKeys.dashboardSnapshot(),
|
||||
});
|
||||
// v1.18.10 / v1.32.19 — the dashboard hero surfaces the briefing
|
||||
// headline from the SNAPSHOT (server-lifted `User.insightsCachedText`),
|
||||
// and the Today hero's lead line is the SAME briefing lifted into the
|
||||
// digest — neither is this advisor cache. A regenerate rewrites that
|
||||
// server cache, so both the snapshot and the digest must refetch.
|
||||
// Regenerate runs on `/insights`, where both are UNMOUNTED, so the
|
||||
// earlier active-only snapshot invalidation only marked it stale (never
|
||||
// refetched, `refetchOnMount: false`) and never touched the digest at
|
||||
// all — returning to `/` then showed the previous briefing under the
|
||||
// greeting AND in the Today lead for up to 120 s. `refetchInactiveDailyReads`
|
||||
// forces both to refetch right here so the return paints the fresh
|
||||
// briefing at once.
|
||||
void refetchInactiveDailyReads(queryClient);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ const READINGS_PAGE_SIZE = 200;
|
||||
*/
|
||||
export function LabBiomarkerDetail({ biomarkerId }: { biomarkerId: string }) {
|
||||
const { user } = useAuth();
|
||||
const { t } = useTranslations();
|
||||
const { t, locale } = useTranslations();
|
||||
const router = useRouter();
|
||||
const queryClient = useQueryClient();
|
||||
// v1.24 — the per-marker description used to live on the labs overview rows.
|
||||
@@ -225,16 +225,32 @@ export function LabBiomarkerDetail({ biomarkerId }: { biomarkerId: string }) {
|
||||
const { data: assessment, isLoading: assessmentLoading } =
|
||||
useInsightBiomarkerAssessment(biomarkerId, readings.length > 0);
|
||||
|
||||
// v1.32.19 — a new reading for this marker changes the same-page AI
|
||||
// assessment card (`insightsBiomarkerAssessment`, mounted here) and the
|
||||
// Insights "what changed since your last panel" read (`insightsLabsChanges`).
|
||||
// Both used to stay on their pre-write text until their own stale window
|
||||
// lapsed; bust them alongside the result list so the assessment repaints as
|
||||
// soon as the reading lands.
|
||||
function invalidateAfterReadingWrite() {
|
||||
queryClient.invalidateQueries({ queryKey: queryKeys.labResults() });
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: queryKeys.insightsBiomarkerAssessment(biomarkerId, locale),
|
||||
});
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: queryKeys.insightsLabsChanges(),
|
||||
});
|
||||
}
|
||||
|
||||
function afterAdd() {
|
||||
setAddOpen(false);
|
||||
queryClient.invalidateQueries({ queryKey: queryKeys.labResults() });
|
||||
invalidateAfterReadingWrite();
|
||||
}
|
||||
|
||||
// v1.30.1 H3 — "Save & add another": same invalidation as `afterAdd`,
|
||||
// minus the close. Useful here too — logging several past readings for
|
||||
// this one biomarker back-to-back without re-opening the sheet each time.
|
||||
function afterAddKeepOpen() {
|
||||
queryClient.invalidateQueries({ queryKey: queryKeys.labResults() });
|
||||
invalidateAfterReadingWrite();
|
||||
}
|
||||
|
||||
function afterEditMarker() {
|
||||
|
||||
@@ -108,6 +108,13 @@ export function LabHistoryList({ readings }: { readings: LabResultDto[] }) {
|
||||
|
||||
function invalidate() {
|
||||
queryClient.invalidateQueries({ queryKey: queryKeys.labResults() });
|
||||
// v1.32.19 — a lab reading edit / delete / restore shifts the two most
|
||||
// recent panels the Insights "what changed since your last panel" card
|
||||
// reads, so bust it too instead of leaving it on its pre-write deltas
|
||||
// until the 60 s stale window lapses.
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: queryKeys.insightsLabsChanges(),
|
||||
});
|
||||
}
|
||||
|
||||
async function restore(id: string) {
|
||||
|
||||
@@ -467,13 +467,45 @@ describe("runTakeAllDue — per-medication loop with failure isolation", () => {
|
||||
expect(vi.mocked(toast.success)).not.toHaveBeenCalledWith(
|
||||
expect.stringContaining("successToast"),
|
||||
);
|
||||
// The landed take must reach every dependent consumer.
|
||||
// The landed take must reach every dependent consumer AND force the two
|
||||
// inactive daily reads (dashboard snapshot + Today digest) to refetch —
|
||||
// the blessed `invalidateMedicationReads` fans out the bundle (N keys)
|
||||
// then invalidates those two with `refetchType: "inactive"`.
|
||||
expect(queryClient.invalidateQueries).toHaveBeenCalledTimes(
|
||||
medicationDependentKeys.length,
|
||||
medicationDependentKeys.length + 2,
|
||||
);
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
it("forces the inactive Today hero + dashboard reads to refetch after a landed take (v1.32.19 stale-hero fix)", async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(okResponse("evt-a"));
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
const queryClient = fakeQueryClient();
|
||||
|
||||
await runTakeAllDue({
|
||||
medications: [dueTwo[0]],
|
||||
t,
|
||||
queryClient,
|
||||
});
|
||||
|
||||
// The batch button lives on `/medications`, where the digest + snapshot
|
||||
// are UNMOUNTED. A bare bundle invalidation (default active refetch) would
|
||||
// leave them stale — so the helper MUST invalidate both with
|
||||
// `refetchType: "inactive"`, which is what actually refetches them.
|
||||
const calls = vi.mocked(queryClient.invalidateQueries).mock.calls;
|
||||
const inactive = calls.filter(
|
||||
([arg]) =>
|
||||
(arg as { refetchType?: string } | undefined)?.refetchType ===
|
||||
"inactive",
|
||||
);
|
||||
const keys = inactive.map(([arg]) =>
|
||||
JSON.stringify((arg as { queryKey?: unknown }).queryKey),
|
||||
);
|
||||
expect(keys).toContain(JSON.stringify(["dashboard", "snapshot"]));
|
||||
expect(keys).toContain(JSON.stringify(["daily", "digest"]));
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
it("reports total failure without invalidating (nothing changed server-side)", async () => {
|
||||
vi.stubGlobal(
|
||||
"fetch",
|
||||
@@ -491,13 +523,15 @@ describe("runTakeAllDue — per-medication loop with failure isolation", () => {
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
it("invalidates exactly the medicationDependentKeys bundle (source pin)", () => {
|
||||
// The bundle includes the dashboard snapshot key (v1.16.11), so a
|
||||
// batch take refreshes the hero dose tally too. Pin the source so a
|
||||
// refactor to a hand-rolled key list cannot slip through.
|
||||
it("routes the batch invalidation through the blessed invalidateMedicationReads (source pin)", () => {
|
||||
// v1.32.19 — the batch take now routes through the one blessed helper,
|
||||
// which fans out `medicationDependentKeys` AND forces the inactive digest
|
||||
// + snapshot to refetch (the maintainer's stale-hero repro). Pin the
|
||||
// source so a revert to a bare bundle invalidation cannot slip through.
|
||||
const src = readFileSync(resolve(__dirname, "../take-all-due.ts"), "utf8");
|
||||
expect(src).toContain(
|
||||
"await invalidateKeys(queryClient, medicationDependentKeys)",
|
||||
expect(src).toContain("await invalidateMedicationReads(queryClient)");
|
||||
expect(src).not.toContain(
|
||||
"invalidateKeys(queryClient, medicationDependentKeys)",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -28,7 +28,11 @@ import { Label } from "@/components/ui/label";
|
||||
import { DateTimeField } from "@/components/ui/date-time-field";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import { invalidateKeys, medicationDependentKeys } from "@/lib/query-keys";
|
||||
import {
|
||||
invalidateKeys,
|
||||
medicationDependentKeys,
|
||||
refetchInactiveDailyReads,
|
||||
} from "@/lib/query-keys";
|
||||
import { apiPost } from "@/lib/api/api-fetch";
|
||||
import type { QueryKey } from "@tanstack/react-query";
|
||||
import type { LedgerSchedule } from "@/components/medications/dose-history-ledger";
|
||||
@@ -174,6 +178,10 @@ export function LedgerAddDialog({
|
||||
...medicationDependentKeys,
|
||||
ledgerKey,
|
||||
]);
|
||||
// A ledger add can land a today-dated dose, so clear the unmounted
|
||||
// Today hero + dashboard too (v1.32.19 — same class as the ledger's
|
||||
// own log/edit/delete sites).
|
||||
await refetchInactiveDailyReads(queryClient);
|
||||
setNudgeOpen(false);
|
||||
onOpenChange(false);
|
||||
} catch {
|
||||
|
||||
@@ -87,6 +87,7 @@ import {
|
||||
invalidateKeys,
|
||||
medicationDependentKeys,
|
||||
queryKeys,
|
||||
refetchInactiveDailyReads,
|
||||
} from "@/lib/query-keys";
|
||||
import type { DoseHistoryStatus } from "@/lib/medications/scheduling/dose-history";
|
||||
import { runUndoIntake } from "@/components/medications/use-medication-intake";
|
||||
@@ -295,6 +296,10 @@ export function DoseHistoryLedger({
|
||||
...medicationDependentKeys,
|
||||
queryKey,
|
||||
]);
|
||||
// The ledger also invalidates its own window key above; the daily
|
||||
// reads (Today hero + dashboard) are unmounted behind the detail
|
||||
// page, so force their inactive refetch too (v1.32.19).
|
||||
await refetchInactiveDailyReads(queryClient);
|
||||
} catch {
|
||||
if (prev) queryClient.setQueryData(queryKey, prev);
|
||||
toast.error(
|
||||
@@ -334,6 +339,10 @@ export function DoseHistoryLedger({
|
||||
...medicationDependentKeys,
|
||||
queryKey,
|
||||
]);
|
||||
// The ledger also invalidates its own window key above; the daily
|
||||
// reads (Today hero + dashboard) are unmounted behind the detail
|
||||
// page, so force their inactive refetch too (v1.32.19).
|
||||
await refetchInactiveDailyReads(queryClient);
|
||||
toast.success(t("medications.detail.intake.edit.savedToast"));
|
||||
} catch {
|
||||
toast.error(t("medications.detail.intake.edit.failed"));
|
||||
@@ -365,6 +374,10 @@ export function DoseHistoryLedger({
|
||||
...medicationDependentKeys,
|
||||
queryKey,
|
||||
]);
|
||||
// The ledger also invalidates its own window key above; the daily
|
||||
// reads (Today hero + dashboard) are unmounted behind the detail
|
||||
// page, so force their inactive refetch too (v1.32.19).
|
||||
await refetchInactiveDailyReads(queryClient);
|
||||
} catch {
|
||||
toast.error(t("medications.detail.intake.edit.failed"));
|
||||
}
|
||||
@@ -380,6 +393,10 @@ export function DoseHistoryLedger({
|
||||
await apiDelete(`/api/medications/${medicationId}/intake/${id}`);
|
||||
toast.success(t("medications.detail.intake.deleteRow.toast"));
|
||||
await invalidateKeys(queryClient, [...medicationDependentKeys, queryKey]);
|
||||
// The ledger also invalidates its own window key above; the daily
|
||||
// reads (Today hero + dashboard) are unmounted behind the detail
|
||||
// page, so force their inactive refetch too (v1.32.19).
|
||||
await refetchInactiveDailyReads(queryClient);
|
||||
} catch {
|
||||
toast.error(t("medications.detail.intake.deleteRow.failed"));
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import { DateTimeField } from "@/components/ui/date-time-field";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { useFormatters, useTranslations } from "@/lib/i18n/context";
|
||||
import { invalidateKeys, medicationDependentKeys } from "@/lib/query-keys";
|
||||
import { invalidateMedicationReads } from "@/lib/query-keys";
|
||||
import { apiPut } from "@/lib/api/api-fetch";
|
||||
|
||||
export interface IntakeEditDialogProps {
|
||||
@@ -129,7 +129,10 @@ function IntakeEditDialogBody({
|
||||
body.takenAt = null;
|
||||
}
|
||||
await apiPut(`/api/medications/${medicationId}/intake/${event.id}`, body);
|
||||
await invalidateKeys(queryClient, medicationDependentKeys);
|
||||
// Editing today's dose (un-skip, retime) changes its due/taken state —
|
||||
// route through the blessed helper so the Today hero + dashboard clear
|
||||
// at once even when they are unmounted behind the detail page.
|
||||
await invalidateMedicationReads(queryClient);
|
||||
toast.success(t("medications.detail.intake.edit.savedToast"));
|
||||
onClose();
|
||||
} catch {
|
||||
|
||||
@@ -40,7 +40,7 @@ import {
|
||||
type IntakeHistorySortKey,
|
||||
} from "@/components/medications/intake-history-list-v2";
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import { invalidateKeys, medicationDependentKeys } from "@/lib/query-keys";
|
||||
import { invalidateMedicationReads } from "@/lib/query-keys";
|
||||
import { apiDelete, apiPost } from "@/lib/api/api-fetch";
|
||||
|
||||
export interface IntakeHistoryEditableProps {
|
||||
@@ -94,7 +94,7 @@ export function IntakeHistoryEditable({
|
||||
await apiPost(`/api/medications/${medicationId}/intake/bulk-delete`, {
|
||||
eventIds: ids,
|
||||
});
|
||||
await invalidateKeys(queryClient, medicationDependentKeys);
|
||||
await invalidateMedicationReads(queryClient);
|
||||
toast.success(t("medications.detail.intake.bulkDelete.toast"));
|
||||
setBulkConfirmOpen(false);
|
||||
clearSelection();
|
||||
@@ -111,7 +111,7 @@ export function IntakeHistoryEditable({
|
||||
const id = pendingDeleteId;
|
||||
try {
|
||||
await apiDelete(`/api/medications/${medicationId}/intake/${id}`);
|
||||
await invalidateKeys(queryClient, medicationDependentKeys);
|
||||
await invalidateMedicationReads(queryClient);
|
||||
toast.success(t("medications.detail.intake.deleteRow.toast"));
|
||||
setPendingDeleteId(null);
|
||||
// Drop the deleted row from the pending selection so the
|
||||
|
||||
@@ -32,7 +32,7 @@ import {
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import { invalidateKeys, medicationDependentKeys } from "@/lib/query-keys";
|
||||
import { invalidateMedicationReads } from "@/lib/query-keys";
|
||||
import { ApiError, apiPost } from "@/lib/api/api-fetch";
|
||||
import {
|
||||
MedicationIntakeImportError,
|
||||
@@ -124,7 +124,10 @@ export function IntakeImportDialog({
|
||||
: ""),
|
||||
);
|
||||
setResultType("success");
|
||||
void invalidateKeys(queryClient, medicationDependentKeys);
|
||||
// An import can land today-dated doses, so clear the Today hero +
|
||||
// dashboard through the blessed helper (they are unmounted behind the
|
||||
// import dialog on the detail page).
|
||||
void invalidateMedicationReads(queryClient);
|
||||
} catch (err) {
|
||||
if (err instanceof MedicationIntakeImportError) {
|
||||
setResult(t("medications.importFailed"));
|
||||
|
||||
@@ -46,11 +46,7 @@ import { Button } from "@/components/ui/button";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import {
|
||||
invalidateKeys,
|
||||
medicationDependentKeys,
|
||||
queryKeys,
|
||||
} from "@/lib/query-keys";
|
||||
import { invalidateMedicationReads, queryKeys } from "@/lib/query-keys";
|
||||
import { apiDelete, apiPut } from "@/lib/api/api-fetch";
|
||||
|
||||
const PAUSE_SWITCH_ID = "medication-detail-pause-switch";
|
||||
@@ -89,7 +85,7 @@ export function LifecycleManageBody({
|
||||
// v1.5.5 C-E3-2 — body carries `{ active }` only; server derives
|
||||
// pausedAt. No client-side pausedAt literal.
|
||||
await apiPut(`/api/medications/${medicationId}`, { active: !pauseNext });
|
||||
await invalidateKeys(queryClient, medicationDependentKeys);
|
||||
await invalidateMedicationReads(queryClient);
|
||||
toast.success(
|
||||
pauseNext
|
||||
? t("medications.detail.zone.pause.pausedToast")
|
||||
@@ -110,7 +106,7 @@ export function LifecycleManageBody({
|
||||
try {
|
||||
const today = new Date().toISOString();
|
||||
await apiPut(`/api/medications/${medicationId}`, { endsOn: today });
|
||||
await invalidateKeys(queryClient, medicationDependentKeys);
|
||||
await invalidateMedicationReads(queryClient);
|
||||
toast.success(t("medications.detail.zone.end.toast"));
|
||||
setEndDialogOpen(false);
|
||||
onAfterAction?.();
|
||||
@@ -246,7 +242,7 @@ export function DangerZoneBody({
|
||||
setTier3aBusy(true);
|
||||
try {
|
||||
await apiDelete(`/api/medications/${medicationId}/intake/purge`);
|
||||
await invalidateKeys(queryClient, medicationDependentKeys);
|
||||
await invalidateMedicationReads(queryClient);
|
||||
toast.success(t("medications.detail.zone.purge.toast"));
|
||||
setPurgeDialogOpen(false);
|
||||
onAfterAction?.();
|
||||
@@ -281,7 +277,7 @@ export function DangerZoneBody({
|
||||
// Fire-and-forget the dependent-bundle invalidation (list /
|
||||
// analytics / compliance / inline chart). Not awaited: navigation
|
||||
// already happened and a transient refetch must not block it.
|
||||
void invalidateKeys(queryClient, medicationDependentKeys);
|
||||
void invalidateMedicationReads(queryClient);
|
||||
} catch {
|
||||
toast.error(t("medications.detail.zone.delete.failed"));
|
||||
setTier3bBusy(false);
|
||||
|
||||
@@ -39,7 +39,7 @@ import type { QueryClient } from "@tanstack/react-query";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { apiPost } from "@/lib/api/api-fetch";
|
||||
import { invalidateKeys, medicationDependentKeys } from "@/lib/query-keys";
|
||||
import { invalidateMedicationReads } from "@/lib/query-keys";
|
||||
import {
|
||||
reduceCurrentWindowStatus,
|
||||
type ScheduleWindowInput,
|
||||
@@ -230,12 +230,17 @@ export async function runTakeAllDue(deps: {
|
||||
}
|
||||
}
|
||||
|
||||
// One invalidation for the whole batch (the bundle includes the
|
||||
// dashboard snapshot key, so the hero dose tally refreshes too). A
|
||||
// zero-success run changed nothing server-side — skip the refetch and
|
||||
// keep the due set as-is for the retry.
|
||||
// One invalidation for the whole batch through the blessed helper: it
|
||||
// fans out the dependent-key bundle AND forces the inactive digest +
|
||||
// snapshot to refetch. The batch button lives on `/medications`, where the
|
||||
// Today hero and dashboard are UNMOUNTED, so a bare bundle invalidation
|
||||
// (default `refetchType: "active"`) marked them stale but never refetched —
|
||||
// the taken doses stayed "due" on the hero until the 120 s poll or a hard
|
||||
// reload (the maintainer's exact repro, v1.32.19). A zero-success run
|
||||
// changed nothing server-side — skip the refetch and keep the due set for
|
||||
// the retry.
|
||||
if (taken > 0) {
|
||||
await invalidateKeys(queryClient, medicationDependentKeys);
|
||||
await invalidateMedicationReads(queryClient);
|
||||
}
|
||||
|
||||
if (failed === 0) {
|
||||
|
||||
@@ -5,44 +5,18 @@ import { useQueryClient, type QueryClient } from "@tanstack/react-query";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import {
|
||||
invalidateKeys,
|
||||
medicationDependentKeys,
|
||||
queryKeys,
|
||||
} from "@/lib/query-keys";
|
||||
import { invalidateMedicationReads } from "@/lib/query-keys";
|
||||
import { apiDelete, apiPost } from "@/lib/api/api-fetch";
|
||||
|
||||
/**
|
||||
* Invalidate every read that reflects a dose's taken/due state after an
|
||||
* intake write. `invalidateKeys` invalidates with the default
|
||||
* `refetchType: "active"`, which only refetches mounted queries — so the
|
||||
* dashboard snapshot AND the Today digest, both inactive while the user is on
|
||||
* the medication card or detail page, are marked stale but never refetched. On
|
||||
* navigating back each remounts under `refetchOnMount: false`, so the pre-write
|
||||
* cache is served and the "due" prompt (snapshot dose tally) plus the digest's
|
||||
* dose-window rail item both linger until a hard reload. Force the inactive
|
||||
* queries to refetch so the dashboard clears as soon as the dose is recorded.
|
||||
*
|
||||
* v1.29.1 — the digest joins the forced-inactive refetch. Its `medsToday`
|
||||
* reads the SAME server snapshot cell the intake route already hard-evicts, so
|
||||
* the refetch returns post-write dose state immediately (no server change
|
||||
* needed — the eviction seam is reused).
|
||||
* Every intake write in this hook clears the Today hero + dashboard through
|
||||
* the one blessed `invalidateMedicationReads` (in `@/lib/query-keys`): it
|
||||
* pairs the `medicationDependentKeys` bundle invalidation with a forced
|
||||
* inactive refetch of the digest + snapshot, so a taken / skipped / undone
|
||||
* dose repaints the moment it lands rather than on the 120 s poll. The helper
|
||||
* used to live inline here (v1.29.1); v1.32.19 lifted it into the factory as
|
||||
* the single canonical entry point every intake surface routes through.
|
||||
*/
|
||||
async function invalidateMedicationReads(
|
||||
queryClient: QueryClient,
|
||||
): Promise<void> {
|
||||
await invalidateKeys(queryClient, medicationDependentKeys);
|
||||
await Promise.all([
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: queryKeys.dashboardSnapshot(),
|
||||
refetchType: "inactive",
|
||||
}),
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: queryKeys.dailyDigest(),
|
||||
refetchType: "inactive",
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
type Translator = (
|
||||
key: string,
|
||||
|
||||
@@ -238,6 +238,21 @@ export function DashboardLayoutSection({ id }: { id: string }) {
|
||||
queryFn: async () => {
|
||||
return apiGet<DashboardLayoutWithToken>("/api/dashboard/widgets");
|
||||
},
|
||||
// v1.32.19 (B-3, belt for the #581 fix) — the home RSC seeds
|
||||
// `dashboardWidgets()` from the dashboard SNAPSHOT layout, which carries
|
||||
// NO `updatedAt` optimistic-concurrency token (it is a token-less
|
||||
// `DashboardLayout`, not the `DashboardLayoutWithToken` this section's GET
|
||||
// returns). Within the global 5-min `staleTime` a visit to `/` then Settings
|
||||
// read that seeded token-less value with no mount refetch, so `readBaseToken()`
|
||||
// returned undefined, the Save sent no `baseUpdatedAt`, and the route's
|
||||
// compat fallback silently reverted to last-write-wins — disabling the
|
||||
// just-shipped 409 belt. Force a mount refetch so this section always holds
|
||||
// its own tokened GET response and every write carries the base token. The
|
||||
// smallest correct option: the alternatives (a distinct seed key, or
|
||||
// threading the token through the snapshot layout) touch the home client and
|
||||
// the server snapshot shape; this is one line, config-independent, and makes
|
||||
// the settings query authoritative for its own tokened read.
|
||||
refetchOnMount: "always",
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user