mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #365] [MERGED] fix: preserve middleware redirect headers in production #511
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#511
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/365
Author: @NathanDrake2406
Created: 3/9/2026
Status: ✅ Merged
Merged: 3/9/2026
Merged by: @james-elicx
Base:
main← Head:fix/middleware-redirect-headers📝 Commits (3)
e1415fffix: preserve middleware redirect headers (Set-Cookie) in production23c8c5atest: update entry template snapshot for redirect header fixb68f76cMerge remote-tracking branch 'origin/main' into fix/middleware-redirect-headers📊 Changes
7 files changed (+87 additions, -5 deletions)
View changed files
📝
packages/vinext/src/deploy.ts(+7 -1)📝
packages/vinext/src/index.ts(+7 -1)📝
packages/vinext/src/server/prod-server.ts(+15 -2)📝
tests/__snapshots__/entry-templates.test.ts.snap(+7 -1)📝
tests/deploy.test.ts(+11 -0)📝
tests/fixtures/pages-basic/middleware.ts(+8 -0)📝
tests/pages-router.test.ts(+32 -0)📄 Description
Summary
Set-Cookieheaders (and other non-internal headers) on redirect responses were silently dropped in production while working correctly in devprod-server.ts(Pages Router prod),deploy.ts(Workers entry),index.ts(inlinerunMiddlewarecodegen)index.ts:2934already handled this correctly — this was a dev/prod parity bugRoot cause
middleware.tscorrectly collects non-internal headers on redirect responses intoresponseHeaders, but the three production consumers ignored it:prod-server.ts:814res.writeHead()only sentLocationdeploy.ts:600new Response()only had{ Location }index.ts:786next()andrewrite())Test plan
tests/deploy.test.ts— verifies generated worker entry referencesresponseHeadersin redirect branchtests/pages-router.test.ts— built entryrunMiddlewarereturnsresponseHeaderswith cookies on redirecttests/pages-router.test.ts— prod server integration:Set-Cookieheaders survive middleware redirect response🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.