mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #939] [MERGED] fix(app-router): reject middleware control responses in route handlers #967
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#967
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/939
Author: @NathanDrake2406
Created: 4/28/2026
Status: ✅ Merged
Merged: 4/28/2026
Merged by: @james-elicx
Base:
main← Head:nathan/fix-app-route-nextresponse-helpers📝 Commits (4)
a630fb0fix(app-router): reject middleware control responses in route handlers0e03861Update tests/app-route-handler-execution.test.ts4f41858Update packages/vinext/src/server/app-route-handler-response.ts19ef0e2fix(app-router): validate route handler ISR regeneration responses📊 Changes
9 files changed (+219 additions, -0 deletions)
View changed files
📝
packages/vinext/src/server/app-route-handler-cache.ts(+2 -0)📝
packages/vinext/src/server/app-route-handler-execution.ts(+2 -0)📝
packages/vinext/src/server/app-route-handler-response.ts(+17 -0)📝
tests/app-route-handler-cache.test.ts(+61 -0)📝
tests/app-route-handler-execution.test.ts(+88 -0)📝
tests/app-route-handler-response.test.ts(+25 -0)📝
tests/app-router.test.ts(+14 -0)➕
tests/fixtures/app-basic/app/api/invalid-next-response-next/route.ts(+5 -0)➕
tests/fixtures/app-basic/app/api/invalid-next-response-rewrite/route.ts(+5 -0)📄 Description
What this changes
App Route handlers now reject
NextResponse.next()andNextResponse.rewrite()responses instead of treating their internal middleware headers as ordinary successful route-handler output.Why
These helpers are middleware control-flow responses. Next.js rejects them after an App Route handler returns:
NextResponse.rewrite()App Route rejection in Next.jsNextResponse.next()App Route rejection in Next.jsNextResponse.next()returning 500Vinext previously accepted those responses and returned
200, which silently diverged from Next.js and could cache or finalize an invalid route-handler response.Approach
The validation lives in the typed route-handler response helper and is invoked from
executeAppRouteHandler()immediately after the user handler returns. That keeps the generated App RSC entry unchanged and prevents invalid middleware-control responses from reaching cache policy, cookie finalization, or response merging.The check matches Next.js semantics:
x-middleware-rewritex-middleware-next: 1500responseValidation
vp test run tests/app-route-handler-execution.test.ts tests/app-router.test.ts -t "rejects middleware control responses"failed before the implementation with200responsesvp fmtvp test run tests/app-route-handler-execution.test.ts tests/app-router.test.tsvp checkRisks / follow-ups
No generated App RSC entry code was added. This intentionally preserves middleware use of
NextResponse.next()andNextResponse.rewrite()while rejecting only App Route handler returns.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.