[PR #614] [CLOSED] fix: detect dynamic API usage in route handlers to prevent stale ISR cache hits #712

Closed
opened 2026-05-06 13:09:44 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/614
Author: @southpolesteve
Created: 3/20/2026
Status: Closed

Base: mainHead: fix/route-handler-dynamic-detection-v3


📝 Commits (3)

  • 43c65ae fix: detect dynamic API usage in route handlers to prevent stale ISR cache hits
  • 0f38c50 fix: clear pipeline dynamic usage before handler execution
  • 60b524f fix: separate proxy-based detection from pipeline dynamic usage

📊 Changes

2 files changed (+336 additions, -21 deletions)

View changed files

📝 packages/vinext/src/entries/app-rsc-entry.ts (+48 -3)
📝 tests/__snapshots__/entry-templates.test.ts.snap (+288 -18)

📄 Description

Summary

Route handlers that access request.headers or request.nextUrl.searchParams are dynamic and should not be served from the ISR cache. This PR adds runtime dynamic detection matching Next.js behavior.

Minimal diff: only changes app-rsc-entry.ts (and snapshots). No changes to headers.ts or the dynamic usage flag type.

Changes

  1. __proxyRouteRequest: Wraps the Request in a Proxy. Accessing .headers or .nextUrl.searchParams calls markDynamicUsage(). Methods are bound to the original target to preserve Web API internal slots.

  2. __dynamicRouteHandlers: A Set that remembers route patterns whose handlers used dynamic APIs. The ISR cache read skips known-dynamic handlers. The Set grows monotonically for the process lifetime (intentional, matches Next.js which determines dynamism statically).

  3. Cache read guard: !__dynamicRouteHandlers.has(handler.pattern) added to the ISR cache read condition.

  4. Background regen: Synthetic request is also wrapped in the Proxy, and dynamic detection adds to the Set.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/614 **Author:** [@southpolesteve](https://github.com/southpolesteve) **Created:** 3/20/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/route-handler-dynamic-detection-v3` --- ### 📝 Commits (3) - [`43c65ae`](https://github.com/cloudflare/vinext/commit/43c65aeb2c7bb6d08a50ebe6e0b9aacbd9a8d61d) fix: detect dynamic API usage in route handlers to prevent stale ISR cache hits - [`0f38c50`](https://github.com/cloudflare/vinext/commit/0f38c5018fc23d930cd16fae751fb2dcf68fab8c) fix: clear pipeline dynamic usage before handler execution - [`60b524f`](https://github.com/cloudflare/vinext/commit/60b524f5cbc6993b76ec278bb5402745f8fd054a) fix: separate proxy-based detection from pipeline dynamic usage ### 📊 Changes **2 files changed** (+336 additions, -21 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/entries/app-rsc-entry.ts` (+48 -3) 📝 `tests/__snapshots__/entry-templates.test.ts.snap` (+288 -18) </details> ### 📄 Description ## Summary Route handlers that access `request.headers` or `request.nextUrl.searchParams` are dynamic and should not be served from the ISR cache. This PR adds runtime dynamic detection matching Next.js behavior. Minimal diff: only changes `app-rsc-entry.ts` (and snapshots). No changes to `headers.ts` or the dynamic usage flag type. ## Changes 1. **`__proxyRouteRequest`**: Wraps the `Request` in a Proxy. Accessing `.headers` or `.nextUrl.searchParams` calls `markDynamicUsage()`. Methods are bound to the original target to preserve Web API internal slots. 2. **`__dynamicRouteHandlers`**: A `Set` that remembers route patterns whose handlers used dynamic APIs. The ISR cache read skips known-dynamic handlers. The Set grows monotonically for the process lifetime (intentional, matches Next.js which determines dynamism statically). 3. **Cache read guard**: `!__dynamicRouteHandlers.has(handler.pattern)` added to the ISR cache read condition. 4. **Background regen**: Synthetic request is also wrapped in the Proxy, and dynamic detection adds to the Set. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:09:44 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#712
No description provided.