perf(medications): stop re-sending the read a nav prefetch just made

The medications list and the compliance summary refetch on every mount,
so a take or skip logged on another device shows on return (#316). The
nav link's hover / touch / focus intent and the route-commit preload
prefetch both reads too, so every visit through a link sent each of
them twice: the prefetch, then the identical request from the mount a
few hundred milliseconds after the first answer landed.

The mount now skips its refetch only when the cached data answers a
prefetch that went to the network for this visit: within the last 10 s,
and since the route last left /medications. A direct load, a return
with an older entry, or a quick return whose prefetch found the entry
still fresh keep the refetch on mount.
This commit is contained in:
Marc-André Bombeck committed 2026-10-04 16:12:04 +02:00
1 parent 2c1369f01b
commit 23961d2280
6 files changed
+229 -18

No files matched your search

+8 -1
View File
@@ -34,7 +34,10 @@ import {
getRecordSessionTransition,
subscribeToRecordSessionTransition,
} from "@/lib/query-keys/record-session-transition";
import { prefetchMedicationsList } from "@/lib/queries/prefetch-medications";
import {
forgetMedicationsPrefetch,
prefetchMedicationsList,
} from "@/lib/queries/prefetch-medications";
import {
getRecordScope,
subscribeToRecordScope,
@@ -245,6 +248,10 @@ function DashboardSnapshotPreloader() {
// intent, so this is the fallback for direct loads + reloads.
if (pathname === "/medications") {
prefetchMedicationsList(queryClient, controller.signal);
} else {
// Off the page: a later prefetch starts a new visit, and an earlier one
// must not excuse the next mount's re-verification.
forgetMedicationsPrefetch();
}
// A transition to an unresolved, refused, or different record scope must
// abort a preloader before its response can be adopted by the next route.