Environment
Nuxt project info:
|
|
| Operating system |
Linux 6.17.11+deb14-cloud-arm64 |
| CPU |
unknown (4 cores) |
| Node.js version |
v22.22.0 |
| nuxt/cli version |
3.32.0 |
| Package manager |
pnpm@10.29.3 |
| Nuxt version |
2.18.1 |
| Nitro version |
2.8.0 |
| Builder |
webpack@4.47.0 |
| Config |
- |
| Modules |
- |
| Build modules |
- |
Reproduction
https://github.com/yckimura/bridge/pull/1/changes
This reproduction includes:
- Test page:
playground/pages/cookie-with-redirect.vue
- Test case (still failing):
test/bridge.test.ts
<template>
<p>cookie-with-redirect.vue</p>
</template>
<script setup>
definePageMeta({
middleware: defineNuxtRouteMiddleware(async () => {
useCookie('redirect-test').value = 'foo'
// Immediately redirect during SSR
await navigateTo('/')
})
})
</script>
it('should respond with set-cookie header even when SSR redirect occurs', async () => {
const res = await fetch('/cookie-with-redirect', { redirect: 'manual' })
// Verify redirect occurred
expect(res.status).toBe(302)
expect(res.headers.get('location')).toEqual('/')
// Verify cookies were set
const cookies = res.headers.get('set-cookie')
expect(cookies).toBeTruthy() // <= Actual: null
expect(cookies).toContain('redirect-test=foo')
})
Describe the bug
When useCookie() is used to set a cookie and navigateTo() is called immediately during SSR, the cookie is not written to the response headers. The cookie value is lost and the Set-Cookie header field is not sent.
Expected
Cookies set via useCookie() should be persisted in the response headers even when an SSR redirect occurs via navigateTo().
Actual
The Set-Cookie header is missing from the redirect response.
Additional context
No response
Logs
https://github.com/yckimura/bridge/actions/runs/22142694863/job/64010989045?pr=1#step:7:238
FAIL test/bridge.test.ts > nuxt composables > should respond with set-cookie header even when SSR redirect occurs
AssertionError: expected null to be truthy
- Expected:
true
+ Received:
null
❯ test/bridge.test.ts:67:21
65| // Verify cookies were set
66| const cookies = res.headers.get('set-cookie')
67| expect(cookies).toBeTruthy()
Test Files 1 failed (1)
| ^
68| expect(cookies).toContain('redirect-test=foo')
69| })
Environment
Nuxt project info:
Linux 6.17.11+deb14-cloud-arm64unknown (4 cores)v22.22.03.32.0pnpm@10.29.32.18.12.8.0webpack@4.47.0---Reproduction
https://github.com/yckimura/bridge/pull/1/changes
This reproduction includes:
playground/pages/cookie-with-redirect.vuetest/bridge.test.tsDescribe the bug
When
useCookie()is used to set a cookie andnavigateTo()is called immediately during SSR, the cookie is not written to the response headers. The cookie value is lost and theSet-Cookieheader field is not sent.Expected
Cookies set via
useCookie()should be persisted in the response headers even when an SSR redirect occurs vianavigateTo().Actual
The
Set-Cookieheader is missing from the redirect response.Additional context
No response
Logs
https://github.com/yckimura/bridge/actions/runs/22142694863/job/64010989045?pr=1#step:7:238