mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #955] [MERGED] fix(app-routes): preserve returned cookie precedence #983
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#983
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/955
Author: @NathanDrake2406
Created: 4/29/2026
Status: ✅ Merged
Merged: 4/29/2026
Merged by: @james-elicx
Base:
main← Head:nathan/app-route-cookie-precedence📝 Commits (1)
f00eefefix(app-routes): preserve returned cookie precedence📊 Changes
4 files changed (+107 additions, -3 deletions)
View changed files
📝
packages/vinext/src/server/app-route-handler-response.ts(+49 -3)📝
tests/app-route-handler-response.test.ts(+29 -0)➕
tests/fixtures/app-basic/app/nextjs-compat/api/cookie-precedence/route.ts(+14 -0)📝
tests/nextjs-compat/set-cookies.test.ts(+15 -0)📄 Description
What this changes
App Route handler finalization now treats cookies produced by
cookies().set()as fallbackSet-Cookievalues. Cookies already present on the returnedResponseare re-applied last, so same-name returned response cookies remain the final values.Why
vinext previously cloned the returned response headers and appended pending mutable cookies afterward. When a route both mutates
cookies()and returns aResponseorNextResponsewith a cookie of the same name, the mutable cookie appeared later inSet-Cookieorder and could override the returned response cookie.Next.js does the opposite. Its
appendMutableCookieshelper records returned response cookies, sets mutable cookies as fallbacks, then sets the original returned cookies as final values: https://github.com/vercel/next.js/blob/canary/packages/next/src/server/web/spec-extension/adapters/request-cookies.ts#L72-L98The App Route module calls that helper after a handler returns a
Response: https://github.com/vercel/next.js/blob/canary/packages/next/src/server/route-modules/app-route/module.ts#L783-L792Approach
The finalizer now extracts returned
Set-Cookienames, deduplicates pending mutable cookies by name so the last mutation wins, skips mutable cookies shadowed by returned response cookies, and then writes fallbacks before the returned response cookies. This mirrors Next.js without normalizing cookie attributes or changing unrelated header behavior.Validation
vp test run tests/app-route-handler-response.test.ts tests/nextjs-compat/set-cookies.test.tsvp check packages/vinext/src/server/app-route-handler-response.ts tests/app-route-handler-response.test.ts tests/nextjs-compat/set-cookies.test.ts tests/fixtures/app-basic/app/nextjs-compat/api/cookie-precedence/route.tsRisks / follow-ups
This is scoped to App Route handler response finalization. Server Action redirect cookie paths already have no returned response cookie to merge against, so they are intentionally outside this change.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.