mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #991] [MERGED] fix(app-router): validate RSC cache-busting params #1005
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#1005
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/991
Author: @NathanDrake2406
Created: 4/30/2026
Status: ✅ Merged
Merged: 5/4/2026
Merged by: @james-elicx
Base:
main← Head:nathan/issue-988-rsc-cache-busting📝 Commits (5)
56f24bbfix(app-router): validate RSC cache-busting paramsd53bfebfix(app-router): hide RSC cache tokens from navigation URLsd699a96fix(app-router): hide RSC cache token from searchParamscf80770fix(app-router): address RSC cache-busting reviewbbdc1d1fix(app-router): preserve HTML redirect destination for direct .rsc navigations📊 Changes
31 files changed (+887 additions, -167 deletions)
View changed files
📝
packages/vinext/src/server/app-browser-entry.ts(+38 -22)📝
packages/vinext/src/server/app-browser-state.ts(+3 -4)📝
packages/vinext/src/server/app-page-boundary.ts(+2 -1)📝
packages/vinext/src/server/app-page-cache.ts(+2 -1)📝
packages/vinext/src/server/app-page-dispatch.ts(+6 -3)📝
packages/vinext/src/server/app-page-execution.ts(+7 -2)📝
packages/vinext/src/server/app-page-response.ts(+3 -2)📝
packages/vinext/src/server/app-page-stream.ts(+2 -1)➕
packages/vinext/src/server/app-rsc-cache-busting.ts(+218 -0)📝
packages/vinext/src/server/app-rsc-handler.ts(+20 -1)📝
packages/vinext/src/server/app-rsc-request-normalization.ts(+5 -5)📝
packages/vinext/src/server/app-server-action-execution.ts(+3 -2)📝
packages/vinext/src/server/middleware-response-headers.ts(+33 -0)📝
packages/vinext/src/shims/link.tsx(+45 -41)📝
packages/vinext/src/shims/navigation.ts(+47 -28)📝
packages/vinext/src/shims/next-shims.d.ts(+4 -0)📝
tests/app-browser-entry.test.ts(+3 -2)📝
tests/app-page-boundary-render.test.ts(+4 -3)📝
tests/app-page-execution.test.ts(+30 -3)📝
tests/app-page-response.test.ts(+43 -2)...and 11 more files
📄 Description
What this changes
Adds a shared App Router RSC cache-busting helper and wires generated RSC entries to reject malformed RSC requests by redirecting them to the canonical
_rscURL. Client-side RSC fetches now sendRSC: 1plus a cache-busting_rscsearch param derived from the request headers that can change the RSC payload.The shared helper also centralizes the App Router RSC
Varyheader set and includes both Next-compatible headers and Vinext-specific variant headers:RSCAcceptNext-Router-State-TreeNext-Router-PrefetchNext-Router-Segment-PrefetchNext-UrlX-Vinext-Interception-ContextX-Vinext-Mounted-SlotsFixes #988.
Why
Next.js now treats the URL as the defensive cache key for RSC requests because some CDNs do not respect
Vary. The relevant upstream behavior is:RSC: 1on Flight fetches: https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/router-reducer/fetch-server-response.ts#L147-L155_rscsearch param before fetching: https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/router-reducer/fetch-server-response.ts#L532-L537Vary, withNext-Urladded for interception-sensitive routes: https://github.com/vercel/next.js/blob/canary/packages/next/src/server/base-server.ts#L2003-L2023 and https://github.com/vercel/next.js/blob/canary/packages/next/src/server/route-modules/app-page/module.ts#L188-L195Vinext uses
.rscURLs rather than the exact same visible URL for HTML and RSC, so the HTML-vs-RSC variant is already separated by pathname. The gap is still real because Vinext's.rscresponse can vary by request headers such as mounted slots and interception context. A CDN that keys only by URL could serve the wrong RSC payload for another slot or interception context.Approach
server/app-rsc-cache-busting.tsas the normal module that owns request headers,_rschashing, canonical redirect validation, and the shared RSCVaryvalue.entries/app-rsc-entry.tsas app-shape codegen: it imports the helper, computesisRscRequest, and delegates validation.Varyvalue.Varytokens when merging middleware headers, so middleware can add its own Vary values without duplicating the base App Router set.Validation
vp checkvp run knip --no-progressvp test run tests/app-rsc-cache-busting.test.ts tests/app-browser-entry.test.ts tests/prefetch-cache.test.ts tests/entry-templates.test.tsvp test run tests/app-rsc-cache-busting.test.ts tests/app-browser-entry.test.ts tests/app-page-cache.test.ts tests/app-page-response.test.ts tests/app-page-boundary-render.test.ts tests/app-page-stream.test.ts tests/app-server-action-execution.test.ts tests/entry-templates.test.tsvp test run tests/app-router.test.ts -t "RSC"Risks / follow-ups
This intentionally adapts the Next.js invariant to Vinext's current
.rscURL model instead of switching Vinext to same-URL Flight fetches. The hash includes Next-compatible RSC variant headers for forward compatibility and the Vinext-specific headers that currently affect payload shape.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.