Repository navigation
fix(server): keep Set-Cookie headers set before responseMeta - #8217
Conversation
In the Node adapters (standalone, Express, Next.js API routes), a cookie
that a middleware or procedure set on `res` was lost when `responseMeta`
also returned a `Set-Cookie` header. For example, with an Express
middleware calling `res.cookie('session', ...)` and `responseMeta`
returning `set-cookie: theme=dark`, the client only got `theme=dark`.
`writeResponse` wrote the response's cookies with
`res.setHeader('set-cookie', cookies)`, which replaces the header. It now
adds them after the cookies already on `res`. When `responseMeta` sets
no cookie, nothing changes. The Fastify adapter already appends cookies.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@sagarrsharmaa is attempting to deploy a commit to the trpc Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
trpc-bot
left a comment
There was a problem hiding this comment.
Cookies set on res before responseMeta now survive, in order, as they already do in the fetch adapter. The test fails on main.
|
This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you. |
Why
resis dropped whenresponseMetaalso sets a cookie.res.cookie('session', …)in an Express middleware andset-cookie: theme=darkfromresponseMeta, the client only getstheme=dark.What
responseMeta's cookies after the ones already onresinstead of replacing them.responseMetasets no cookie, nothing changes. Fastify already appends cookies, so it is unchanged.Links
None
Alternatives considered
res.appendHeader(): shorter, but HTTP/2 responses only have it from Node 20.12, and some hosts pass partial response objects.getHeaderplussetHeaderworks everywhere.Testing
packages/tests/server/regression/nodeSetCookieHeaders.test.tssets a cookie in a middleware and one in a procedure, on a standalone and an Express server, next to aresponseMetacookie. Onmainonly theresponseMetacookie comes back.AI model
Opus 5.5
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.Summary by CodeRabbit