Deduplicate middleware Set-Cookie headers by cookie identity#93740
Draft
RajvardhanPatil07 wants to merge 1 commit intovercel:canaryfrom
Draft
Deduplicate middleware Set-Cookie headers by cookie identity#93740RajvardhanPatil07 wants to merge 1 commit intovercel:canaryfrom
RajvardhanPatil07 wants to merge 1 commit intovercel:canaryfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
This updates the middleware cookie merge path so later
Set-Cookievalues replace matching middleware cookies by cookie identity: name, domain, and path.That means when middleware sets a cookie and a later Server Action sets the same cookie, the final response only includes the later value instead of sending duplicate
Set-Cookieheaders for the same cookie.Why
Fixes #69785.
Middleware cookies are stored on request metadata and later merged into response
Set-Cookieheaders. The previous merge only deduped exact string matches, so values likesession=from-middleware; Path=/andsession=from-action; Path=/both survived even though the latter should take precedence.Notes
The identity-based merge is only applied when middleware cookies are present. Non-middleware
Set-Cookiebehavior is preserved, including multiple same-name cookies set by other response paths.Validation
pnpm testonly packages/next/src/server/lib/patch-set-header.test.ts --runInBandpnpm prettier --check packages/next/src/server/lib/patch-set-header.ts packages/next/src/server/lib/patch-set-header.test.ts packages/next/src/server/web/spec-extension/cookies.tspnpm --filter next build