-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Description
Environment
- Operating System:
Darwin
- Node Version:
v22.14.0
- Nuxt Version:
3.17.5
- CLI Version:
3.25.1
- Nitro Version:
2.11.12
- Package Manager:
pnpm@10.11.0
- Builder:
-
- User Config:
compatibilityDate
,devtools
- Runtime Modules:
-
- Build Modules:
-
Reproduction
Couldn't do it in StackBlitz because it's a cookie thing but here is a minimal reproduction to run locally: https://github.com/pgraug/nuxt-repro-forgets-set-cookie-on-error
Describe the bug
When setting multiple cookies during SSR and encountering an error, only the last cookie you set will be included in the response headers instead of one set-cookie
header per cookie.
This is due to one use of setResponseHeader
in Nuxt's Nitro error handler (permalink to line) that overwrites the previous set-cookie
headers each time it sees a new one.
I propose two possible solutions:
- Using
appendResponseHeader
inside the loop instead since it handles multiple cookies with the same by converting them to an array. Only thing I'm not sure about with this is whether there are some unintended side-effects likecontent-type
becoming an array as well because the response already had one. - Doing an
Array.reduce
onArray.from(res.headers.entries())
to group headers of the same name into an array and then usingsetResponseHeaders
to set them all at once. This should be safe from any unintended side-effects but is more complex.
The first solution seems the simplest but I would love your thoughts on whether it would have any unintended consequences. I can make the PR for it if you're okay with my solution.
Additional context
No response