mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #613] [CLOSED] fix: detect dynamic API usage in route handlers to prevent stale ISR cache hits #713
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#713
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/613
Author: @southpolesteve
Created: 3/20/2026
Status: ❌ Closed
Base:
main← Head:fix/route-handler-dynamic-detection-v2📝 Commits (2)
72e3078fix: detect dynamic API usage in route handlers to prevent stale ISR cache hitse0b9beedebug: pass raw request to handler (test if proxy is the cause)📊 Changes
6 files changed (+417 additions, -42 deletions)
View changed files
📝
packages/vinext/src/build/prerender.ts(+1 -1)📝
packages/vinext/src/entries/app-rsc-entry.ts(+55 -2)📝
packages/vinext/src/shims/headers.ts(+12 -8)📝
packages/vinext/src/shims/unified-request-context.ts(+1 -1)📝
tests/__snapshots__/entry-templates.test.ts.snap(+330 -12)📝
tests/unified-request-context.test.ts(+18 -18)📄 Description
Summary
Route handlers that access
request.headersorrequest.nextUrl.searchParamsare dynamic and should not be served from the ISR cache. This PR adds runtime dynamic detection matching Next.js behavior.Changes
__proxyRouteRequest: Wraps theRequestpassed to route handlers in a Proxy. Accessing.headersor.nextUrl.searchParamscallsmarkDynamicUsage(). Methods are bound to the original target to preserve Web API internal slots (.json(),.text(), etc.).__dynamicRouteHandlers: A module-levelSetthat remembers route patterns whose handlers used dynamic APIs. The ISR cache read condition checks this set and skips the cache for known-dynamic handlers.dynamicUsageCount: Replaces the booleandynamicUsageDetectedflag with a counter, enabling future counter-based bracketing of handler execution.Why not query-string-in-cache-key?
James pointed out that including query strings in the cache key diverges from Next.js, which uses pathname-only keys (source). In Next.js, handlers that read searchParams are detected as dynamic and never cached at all. This PR matches that behavior.
Proxy granularity
request.methodrequest.url(string)request.nextUrl.pathnamerequest.nextUrl.searchParamsrequest.headersThe one gap (same as Next.js):
new URL(request.url).searchParamsbypasses the Proxy.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.