mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #865] [MERGED] fix: emit no-store Cache-Control for revalidate = 0 route handlers #907
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#907
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/cloudflare/vinext/pull/865
Author: @NathanDrake2406
Created: 4/21/2026
Status: ✅ Merged
Merged: 4/21/2026
Merged by: @james-elicx
Base:
main← Head:fix/route-handler-revalidate-zero📝 Commits (2)
726c36atest: cover revalidate = 0 route handler never-cache semantics1b4fabafix: emit no-store Cache-Control for revalidate = 0 route handlers📊 Changes
4 files changed (+90 additions, -7 deletions)
View changed files
📝
packages/vinext/src/server/app-route-handler-policy.ts(+19 -5)📝
packages/vinext/src/server/app-route-handler-response.ts(+12 -0)📝
tests/app-route-handler-policy.test.ts(+42 -2)📝
tests/app-route-handler-response.test.ts(+17 -0)📄 Description
What this changes
Route handlers exporting
export const revalidate = 0now emit the canonical no-storeCache-Controlheader (private, no-cache, no-store, max-age=0, must-revalidate) that Next.js emits in the same situation. Previously they emitted noCache-Controlat all.Why
getAppRouteHandlerRevalidateSecondscollapsedrevalidate = 0intonullby filtering on> 0. Every downstream gate (shouldReadAppRouteHandlerCache,shouldApplyAppRouteHandlerRevalidateHeader,shouldWriteAppRouteHandlerCache) short-circuits whenrevalidateSeconds === null, so the framework skipped the header write. CDNs and browsers then applied heuristic caching to a response the author had explicitly opted out of.The page path already handles this correctly:
resolveAppPageRscResponsePolicyandresolveAppPageHtmlResponsePolicyeach branch onrevalidateSeconds === 0and return a no-store policy. The route handler path was the asymmetric one.Approach
Preserve
0as a distinct value in the policy helper. UseNumber.isFinitesoNaNandInfinitystill fall tonullalongside negatives.Split the three downstream gates along semantic lines:
shouldReadAppRouteHandlerCacheandshouldWriteAppRouteHandlerCachekeep> 0. A never-cache handler must not serve from ISR and must not persist to ISR.shouldApplyAppRouteHandlerRevalidateHeaderkeeps!== null. It must fire for0so the header is written.buildRouteHandlerCacheControlbranches on0first and returns the canonical Next.js no-store string (matches.nextjs-ref/packages/next/src/server/lib/cache-control.ts:28-29).Non-goals: did not touch the App Router page paths (they were already correct), the Pages Router
buildPagesCacheResponsehelper (separate codepath, separate review), or the generated RSC entry (no change needed, the helper changes flow through).Validation
vp test run tests/app-route-handler-policy.test.ts tests/app-route-handler-response.test.ts tests/app-route-handler-cache.test.ts tests/app-route-handler-execution.test.ts- 26 passing.vp checkon the four touched files - clean.tests/app-route-handler-policy.test.tsfails withexpected 0, got nullon the helper,expected true to be falseon the read/write gates withrevalidateSeconds: 0, andtests/app-route-handler-response.test.tsfails withexpected "private, no-cache, no-store, max-age=0, must-revalidate" to be "s-maxage=0, stale-while-revalidate".Risks / follow-ups
buildPagesCacheResponse(packages/vinext/src/server/pages-page-data.ts:163) uses an SWR template without a0branch. It is called with arevalidateSecondsderived fromgetStaticProps, which has different semantics, so it is out of scope here. Worth a follow-up audit.resolveAppRouteHandlerSpecialError(packages/vinext/src/server/app-route-handler-policy.ts:147) and the equivalent helper inapp-page-execution.tscurrently parseNEXT_REDIRECTdigests without validating the number of;-delimited parts. A malformed digest will silently decodeundefinedor parseNaNas a status code. Not touched in this PR. Open issue / follow-up work.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.