[PR #449] [CLOSED] fix: App Router RSC dev invalidation parity across requests #579

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

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/449
Author: @JaredStowell
Created: 3/11/2026
Status: Closed

Base: mainHead: jstowell/fix-app-router-rsc-request-invalidation


📝 Commits (10+)

  • 6b22307 Ensure static export token header
  • 3da870e Fix dotted App Router invalidation
  • 06efb46 Fix App Router invalidation for dots
  • 61aca7b Fix App Router dot routing invalid
  • df7d17e Fix App Router invalidation bugs
  • 607120d Fix App Router invalidation regresss
  • dd12f30 Fix App Router rewrite invalidation
  • bf97e72 Add App Router and headers regressions
  • f3340fb Fix headers shim lint warning
  • 2c8c549 Harden App Router prepared request handoff

📊 Changes

20 files changed (+1823 additions, -132 deletions)

View changed files

📝 packages/vinext/src/build/static-export.ts (+20 -2)
📝 packages/vinext/src/entries/app-rsc-entry.ts (+89 -12)
📝 packages/vinext/src/index.ts (+647 -23)
📝 packages/vinext/src/server/app-router-entry.ts (+10 -0)
packages/vinext/src/server/app-router-prepared-state.ts (+120 -0)
📝 packages/vinext/src/server/prod-server.ts (+2 -0)
📝 packages/vinext/src/shims/headers.ts (+5 -3)
📝 tests/__snapshots__/entry-templates.test.ts.snap (+488 -72)
📝 tests/app-router.test.ts (+230 -3)
tests/fixtures/app-basic/app/nextjs-compat/fresh-metadata/sitemap.ts (+9 -0)
tests/fixtures/app-basic/app/nextjs-compat/isr-dotted/[slug]/page.tsx (+12 -0)
tests/fixtures/app-basic/app/nextjs-compat/isr-imported-module/data.ts (+1 -0)
tests/fixtures/app-basic/app/nextjs-compat/isr-imported-module/page.tsx (+5 -0)
tests/fixtures/app-basic/app/nextjs-compat/isr-shared-module/page.tsx (+5 -0)
📝 tests/fixtures/app-basic/middleware.ts (+5 -0)
📝 tests/fixtures/app-basic/next.config.ts (+17 -0)
tests/fixtures/app-basic/pages/mw-pages-to-app-rewrite.tsx (+3 -0)
tests/fixtures/shared/rsc-shared-now.ts (+1 -0)
📝 tests/nextjs-compat/app-rendering.test.ts (+138 -17)
📝 tests/shims.test.ts (+16 -0)

📄 Description

Fix App Router dev-mode RSC invalidation so server modules re-execute with request freshness.

This change removes the old root-scoped invalidation heuristic and replaces it with route-closure invalidation:

  • match the App Router route for the request
  • collect that route's page/layout/template/boundary modules
  • invalidate the imported RSC dependency closure from those route roots
  • keep the virtual RSC entry invalidated per request

It also fixes mixed app/pages behavior by invalidating on the actual Pages -> App handoff path after middleware/config rewrites determine the final App Router URL.

Why

The previous approach was inadequate:

  • it could miss shared/workspace modules outside the app root
  • it could invalidate vinext internals unnecessarily
  • it classified some mixed app/pages requests too early, before rewrites finalized the App Router target

Tests

Added regressions for:

  • imported server modules outside the app root re-executing across requests
  • middleware rewriting a Pages route into an App Router route still getting fresh RSC execution

Verification

Passed:

  • pnpm test tests/nextjs-compat/app-rendering.test.ts
  • pnpm test tests/app-router.test.ts -t "re-executes App Router modules when middleware rewrites a Pages path into app/"
  • pnpm test tests/app-router.test.ts -t "App Router Static export"
  • pnpm run fmt
  • pnpm run typecheck

🔄 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/449 **Author:** [@JaredStowell](https://github.com/JaredStowell) **Created:** 3/11/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `jstowell/fix-app-router-rsc-request-invalidation` --- ### 📝 Commits (10+) - [`6b22307`](https://github.com/cloudflare/vinext/commit/6b2230714d369390cf1c593ce0ef2c22558574d8) Ensure static export token header - [`3da870e`](https://github.com/cloudflare/vinext/commit/3da870e4c6d8fffe31aa915ce9a3a88f56247759) Fix dotted App Router invalidation - [`06efb46`](https://github.com/cloudflare/vinext/commit/06efb463b86edb793838fb52814fb17af0fefce2) Fix App Router invalidation for dots - [`61aca7b`](https://github.com/cloudflare/vinext/commit/61aca7b5d643f31af0abd557e18286f9384169ce) Fix App Router dot routing invalid - [`df7d17e`](https://github.com/cloudflare/vinext/commit/df7d17e945d04c547f17910300c9cb557a45422f) Fix App Router invalidation bugs - [`607120d`](https://github.com/cloudflare/vinext/commit/607120dae3f6a288ca85093856d87908b7bd4199) Fix App Router invalidation regresss - [`dd12f30`](https://github.com/cloudflare/vinext/commit/dd12f30231b8160c84379cea8d7e347555a4b725) Fix App Router rewrite invalidation - [`bf97e72`](https://github.com/cloudflare/vinext/commit/bf97e72797194c43bd2016d2a823aea9022a71b0) Add App Router and headers regressions - [`f3340fb`](https://github.com/cloudflare/vinext/commit/f3340fb3551ad577e8dd5c9e889fc1fbe45fbd95) Fix headers shim lint warning - [`2c8c549`](https://github.com/cloudflare/vinext/commit/2c8c5492a27ebe7048b5902b0acf86b79920eda1) Harden App Router prepared request handoff ### 📊 Changes **20 files changed** (+1823 additions, -132 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/build/static-export.ts` (+20 -2) 📝 `packages/vinext/src/entries/app-rsc-entry.ts` (+89 -12) 📝 `packages/vinext/src/index.ts` (+647 -23) 📝 `packages/vinext/src/server/app-router-entry.ts` (+10 -0) ➕ `packages/vinext/src/server/app-router-prepared-state.ts` (+120 -0) 📝 `packages/vinext/src/server/prod-server.ts` (+2 -0) 📝 `packages/vinext/src/shims/headers.ts` (+5 -3) 📝 `tests/__snapshots__/entry-templates.test.ts.snap` (+488 -72) 📝 `tests/app-router.test.ts` (+230 -3) ➕ `tests/fixtures/app-basic/app/nextjs-compat/fresh-metadata/sitemap.ts` (+9 -0) ➕ `tests/fixtures/app-basic/app/nextjs-compat/isr-dotted/[slug]/page.tsx` (+12 -0) ➕ `tests/fixtures/app-basic/app/nextjs-compat/isr-imported-module/data.ts` (+1 -0) ➕ `tests/fixtures/app-basic/app/nextjs-compat/isr-imported-module/page.tsx` (+5 -0) ➕ `tests/fixtures/app-basic/app/nextjs-compat/isr-shared-module/page.tsx` (+5 -0) 📝 `tests/fixtures/app-basic/middleware.ts` (+5 -0) 📝 `tests/fixtures/app-basic/next.config.ts` (+17 -0) ➕ `tests/fixtures/app-basic/pages/mw-pages-to-app-rewrite.tsx` (+3 -0) ➕ `tests/fixtures/shared/rsc-shared-now.ts` (+1 -0) 📝 `tests/nextjs-compat/app-rendering.test.ts` (+138 -17) 📝 `tests/shims.test.ts` (+16 -0) </details> ### 📄 Description Fix App Router dev-mode RSC invalidation so server modules re-execute with request freshness. This change removes the old root-scoped invalidation heuristic and replaces it with route-closure invalidation: - match the App Router route for the request - collect that route's page/layout/template/boundary modules - invalidate the imported RSC dependency closure from those route roots - keep the virtual RSC entry invalidated per request It also fixes mixed app/pages behavior by invalidating on the actual Pages -> App handoff path after middleware/config rewrites determine the final App Router URL. ## Why The previous approach was inadequate: - it could miss shared/workspace modules outside the app root - it could invalidate vinext internals unnecessarily - it classified some mixed app/pages requests too early, before rewrites finalized the App Router target ## Tests Added regressions for: - imported server modules outside the app root re-executing across requests - middleware rewriting a Pages route into an App Router route still getting fresh RSC execution ## Verification Passed: - `pnpm test tests/nextjs-compat/app-rendering.test.ts` - `pnpm test tests/app-router.test.ts -t "re-executes App Router modules when middleware rewrites a Pages path into app/"` - `pnpm test tests/app-router.test.ts -t "App Router Static export"` - `pnpm run fmt` - `pnpm run typecheck` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:08:52 +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#579
No description provided.