Files
cloudflare__vinext/tests/cache-control.test.ts
T
Nathan Nguyen 937f5d6a09 fix(app-router): read indefinite app page cache entries (#1129)
* fix(app-router): read indefinite app page cache entries

App pages with revalidate=false currently normalize to Infinity, but the app-page cache read gate excludes Infinity. Pre-rendered static app pages can be seeded into the ISR cache and still miss that cache on every production request.

The cache read policy now treats positive Infinity as read-eligible while preserving force-dynamic, production, RSC, and nonce guards. Cached indefinite responses are normalized to the same static one-year Cache-Control header used by fresh revalidate=false responses, so cache hits do not emit s-maxage=Infinity.

Tests cover the dispatch cache hit path and the shared cached Cache-Control helper.

* chore: rerun ci

* chore: rerun ci
2026-05-07 11:23:28 +00:00

48 lines
1.7 KiB
TypeScript

import { describe, expect, it } from "vite-plus/test";
import {
buildCachedRevalidateCacheControl,
buildRevalidateCacheControl,
} from "../packages/vinext/src/server/cache-control.js";
describe("cache-control helpers", () => {
it("uses Next.js expire minus revalidate for finite SWR windows", () => {
expect(buildRevalidateCacheControl(60, 300)).toBe("s-maxage=60, stale-while-revalidate=240");
});
it("omits stale-while-revalidate when expire does not exceed revalidate", () => {
expect(buildRevalidateCacheControl(300, 300)).toBe("s-maxage=300");
});
it("preserves vinext's legacy unbounded SWR header when expire is unknown", () => {
expect(buildRevalidateCacheControl(60)).toBe("s-maxage=60, stale-while-revalidate");
});
it("uses route policy for STALE cached responses when expire is known", () => {
expect(buildCachedRevalidateCacheControl("STALE", 60, 300)).toBe(
"s-maxage=60, stale-while-revalidate=240",
);
});
it("uses route policy for HIT cached responses when expire is known", () => {
expect(buildCachedRevalidateCacheControl("HIT", 60, 300)).toBe(
"s-maxage=60, stale-while-revalidate=240",
);
});
it("uses static cache-control for cached indefinite responses", () => {
expect(buildCachedRevalidateCacheControl("HIT", Infinity)).toBe(
"s-maxage=31536000, stale-while-revalidate",
);
});
it("preserves legacy STALE cached response headers when expire is unknown", () => {
expect(buildCachedRevalidateCacheControl("STALE", 60)).toBe(
"s-maxage=0, stale-while-revalidate",
);
});
it("keeps the full expire window when revalidate is zero", () => {
expect(buildRevalidateCacheControl(0, 300)).toBe("s-maxage=0, stale-while-revalidate=300");
});
});