mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(nuxt): don't share object between raw cookie and cookie ref (#25255)
This commit is contained in:
parent
6c6032782f
commit
6ca3a6fecb
@ -61,6 +61,8 @@ export function useCookie<T = string | null | undefined> (name: string, _opts?:
|
||||
const callback = () => {
|
||||
if (opts.readonly || isEqual(cookie.value, cookies[name])) { return }
|
||||
writeClientCookie(name, cookie.value, opts as CookieSerializeOptions)
|
||||
|
||||
cookies[name] = klona(cookie.value)
|
||||
channel?.postMessage(opts.encode(cookie.value as T))
|
||||
}
|
||||
|
||||
@ -107,7 +109,7 @@ export function useCookie<T = string | null | undefined> (name: string, _opts?:
|
||||
return cookie as CookieRef<T>
|
||||
}
|
||||
|
||||
function readRawCookies (opts: CookieOptions = {}): Record<string, string> | undefined {
|
||||
function readRawCookies (opts: CookieOptions = {}): Record<string, unknown> | undefined {
|
||||
if (import.meta.server) {
|
||||
return parse(getRequestHeader(useRequestEvent(), 'cookie') || '', opts)
|
||||
} else if (import.meta.client) {
|
||||
|
@ -501,6 +501,8 @@ describe('nuxt composables', () => {
|
||||
expect(await extractCookie()).toEqual({ foo: 'bar' })
|
||||
await page.getByRole('button').click()
|
||||
expect(await extractCookie()).toEqual({ foo: 'baz' })
|
||||
await page.getByRole('button').click()
|
||||
expect(await extractCookie()).toEqual({ foo: 'bar' })
|
||||
await page.close()
|
||||
})
|
||||
})
|
||||
|
2
test/fixtures/basic/pages/cookies.vue
vendored
2
test/fixtures/basic/pages/cookies.vue
vendored
@ -20,7 +20,7 @@ const objectCookie = useCookie('browser-object-default', {
|
||||
<div>
|
||||
<div>cookies testing page</div>
|
||||
<pre>{{ objectCookie }}</pre>
|
||||
<button @click="objectCookie.foo = 'baz'">
|
||||
<button @click="objectCookie.foo === 'baz' ? objectCookie.foo = 'bar' : objectCookie.foo = 'baz'">
|
||||
Change cookie
|
||||
</button>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user