cloudflare / cloudflare/vinext
App Router: preserve final internal rewrite path after Proxy rewrites
- Dominant language
- TypeScript
- Stars
- 8.8k
- Forks
- 406
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 120
Description
## Next.js Change
**Commit:** [`4d36801`](https://github.com/vercel/next.js/commit/4d36801fdbc0b6b97c497c6c1820005477b9aa6d)
**PR:** [#97953](https://github.com/vercel/next.js/pull/97953)
## What changed
After a Proxy (middleware) rewrite, Next.js route resolution may apply a later internal rewrite for an intercepted route. The final marker-bearing pathname is sent in `x-nextjs-rewritten-path`. Previously, the accumulated Proxy response headers were reapplied after route resolution and overwrote that final value with the earlier markerless pathname.
Next.js now also updates the accumulated response-header map when it sets the final internal rewritten pathname, so the last rewrite remains authoritative. This preserves dynamic intercepted-route params after a locale-injecting Proxy rewrite.
## Impact on vinext
Vinext handles middleware rewrites and App Router interception routing. Its final route-resolution rewrite must take precedence over any earlier middleware rewrite in the RSC response. Otherwise the client can parse intercepted dynamic params from a stale pathname and truncate their values.
## Acceptance criteria
- [ ] When middleware rewrites a request and route resolution later produces an internal interception rewrite, emit the final pathname in the RSC rewritten-path header.
- [ ] Ensure subsequent response-header merging cannot restore the earlier middleware rewrite value.
- [ ] Preserve existing external rewrite and query rewrite behavior.
- [ ] Add a regression fixture for a dynamic intercepted route behind a locale-injecting middleware rewrite.
- [ ] Verify the regression in development and production.
## Related
- #1364 - Basic interception segment parsing and route-resolution support
- #1369 - Intercepted and parallel-route state preservation across traversal and refresh
- Upstream regression: `test/e2e/app-dir/interception-dynamic-segment-middleware/`
Contributor guide
Research direction
Start by tracing Vinext’s middleware rewrite and App Router interception-routing entry points, then inspect how the RSC rewritten-path header is merged after route resolution. Use the upstream regression reference at test/e2e/app-dir/interception-dynamic-segment-middleware/ as the behavioral guide. Done means the final marker-bearing pathname survives merging, existing external and query rewrites remain intact, and the fixture passes in development and production.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- next.js, typescript, vite
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100