mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 15:15:19 +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 = () => {
|
const callback = () => {
|
||||||
if (opts.readonly || isEqual(cookie.value, cookies[name])) { return }
|
if (opts.readonly || isEqual(cookie.value, cookies[name])) { return }
|
||||||
writeClientCookie(name, cookie.value, opts as CookieSerializeOptions)
|
writeClientCookie(name, cookie.value, opts as CookieSerializeOptions)
|
||||||
|
|
||||||
|
cookies[name] = klona(cookie.value)
|
||||||
channel?.postMessage(opts.encode(cookie.value as T))
|
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>
|
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) {
|
if (import.meta.server) {
|
||||||
return parse(getRequestHeader(useRequestEvent(), 'cookie') || '', opts)
|
return parse(getRequestHeader(useRequestEvent(), 'cookie') || '', opts)
|
||||||
} else if (import.meta.client) {
|
} else if (import.meta.client) {
|
||||||
|
@ -501,6 +501,8 @@ describe('nuxt composables', () => {
|
|||||||
expect(await extractCookie()).toEqual({ foo: 'bar' })
|
expect(await extractCookie()).toEqual({ foo: 'bar' })
|
||||||
await page.getByRole('button').click()
|
await page.getByRole('button').click()
|
||||||
expect(await extractCookie()).toEqual({ foo: 'baz' })
|
expect(await extractCookie()).toEqual({ foo: 'baz' })
|
||||||
|
await page.getByRole('button').click()
|
||||||
|
expect(await extractCookie()).toEqual({ foo: 'bar' })
|
||||||
await page.close()
|
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>
|
||||||
<div>cookies testing page</div>
|
<div>cookies testing page</div>
|
||||||
<pre>{{ objectCookie }}</pre>
|
<pre>{{ objectCookie }}</pre>
|
||||||
<button @click="objectCookie.foo = 'baz'">
|
<button @click="objectCookie.foo === 'baz' ? objectCookie.foo = 'bar' : objectCookie.foo = 'baz'">
|
||||||
Change cookie
|
Change cookie
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user