fix: bypass Data Cache on live park/ride pages so navigation shows fresh data
The ride detail and park pages fetched with `next: { revalidate: 60 }`,
which is stale-while-revalidate. After hours of no traffic the Data Cache
held a morning snapshot; the first click served that stale value and only
the second request (e.g. a browser refresh) got the just-revalidated
payload. The endpoint also bundles live state with chart history, so one
stale fetch made the whole page wrong.
Switch the live-data fetches to `cache: "no-store"`. The calendar-month
fetch keeps its 5-min ISR since operating hours change slowly.
This commit is contained in:
@@ -73,7 +73,7 @@ export default async function ParkPage({ params, searchParams }: PageProps) {
|
|||||||
),
|
),
|
||||||
apiFetch<RidesResponse>(
|
apiFetch<RidesResponse>(
|
||||||
`/api/parks/${id}/rides`,
|
`/api/parks/${id}/rides`,
|
||||||
{ revalidate: 60 },
|
{ noStore: true },
|
||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ export default async function RideDetailPage({ params, searchParams }: PageProps
|
|||||||
let res: Response;
|
let res: Response;
|
||||||
try {
|
try {
|
||||||
res = await fetch(`${getBackendUrl()}/api/parks/${id}/rides/${slug}`, {
|
res = await fetch(`${getBackendUrl()}/api/parks/${id}/rides/${slug}`, {
|
||||||
next: { revalidate: 60 },
|
cache: "no-store",
|
||||||
});
|
});
|
||||||
} catch {
|
} catch {
|
||||||
return <ErrorState parkId={id} parkName={park.name} />;
|
return <ErrorState parkId={id} parkName={park.name} />;
|
||||||
|
|||||||
+6
-5
@@ -31,13 +31,14 @@ export function getBackendUrl(): string {
|
|||||||
*/
|
*/
|
||||||
export async function apiFetch<T>(
|
export async function apiFetch<T>(
|
||||||
path: string,
|
path: string,
|
||||||
options: { revalidate?: number } = {},
|
options: { revalidate?: number; noStore?: boolean } = {},
|
||||||
): Promise<T | null> {
|
): Promise<T | null> {
|
||||||
const { revalidate = 60 } = options;
|
const { revalidate = 60, noStore = false } = options;
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${getBackendUrl()}${path}`, {
|
const res = await fetch(
|
||||||
next: { revalidate },
|
`${getBackendUrl()}${path}`,
|
||||||
});
|
noStore ? { cache: "no-store" } : { next: { revalidate } },
|
||||||
|
);
|
||||||
if (!res.ok) return null;
|
if (!res.ok) return null;
|
||||||
return (await res.json()) as T;
|
return (await res.json()) as T;
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
Reference in New Issue
Block a user