Review

Cache cold-chain excursion detail loader

Pharma logistics ops bounce between the excursion list and a single sensor report dozens of times per shift. Wire the detail route loader with explicit staleTime and gcTime so revisiting a report reuses cached payload instead of re-fetching the sensor API on every navigation.

TanStack RouterTier 3routercachingloaders

Click a line to flag it, pick one or more labels, then submit. If the change looks correct, approve it.

routes/excursions/$excursionId.tsx+7-3
1414import { createFileRoute } from "@tanstack/react-router";
1515import { fetchExcursionReport } from "@/api/cold-chain";
1616import { ExcursionDetail } from "@/components/excursions/ExcursionDetail";
1717
1818export const Route = createFileRoute("/excursions/$excursionId")({
19- loader: async ({ params }) => {
20- return fetchExcursionReport(params.excursionId);
21- },
19+ // Fresh for 30s while ops page between list and detail; keep unused
20+ // report entries 10m so back-navigation stays instant mid-shift.
21+ staleTime: 30_000,
22+ gcTime: 10 * 60_000,
23+ loader: async ({ params }) => {
24+ return fetchExcursionReport(params.excursionId);
25+ },
2226 component: ExcursionDetailPage,
2327});
2428
2529function ExcursionDetailPage() {
2630 const report = Route.useLoaderData();
2731 return <ExcursionDetail report={report} />;
2832}