mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-21 21:25:11 +00:00
fix(nuxt): broadcast cookie change in correct format (#25598)
This commit is contained in:
parent
c41acfb7ca
commit
876d910c3f
@ -69,7 +69,7 @@ export function useCookie<T = string | null | undefined> (name: string, _opts?:
|
||||
writeClientCookie(name, cookie.value, opts as CookieSerializeOptions)
|
||||
|
||||
cookies[name] = klona(cookie.value)
|
||||
channel?.postMessage(opts.encode(cookie.value as T))
|
||||
channel?.postMessage({ value: opts.encode(cookie.value as T) })
|
||||
}
|
||||
|
||||
const handleChange = (data: { value?: any, refresh?: boolean }) => {
|
||||
|
@ -490,11 +490,13 @@ describe('nuxt composables', () => {
|
||||
expect(await extractCookie()).toEqual({ foo: 'bar' })
|
||||
await page.getByText('Change cookie').click()
|
||||
expect(await extractCookie()).toEqual({ foo: 'baz' })
|
||||
let text = await page.innerText('pre')
|
||||
expect(text).toContain('baz')
|
||||
await page.getByText('Change cookie').click()
|
||||
expect(await extractCookie()).toEqual({ foo: 'bar' })
|
||||
await page.evaluate(() => document.cookie = 'updated=foobar')
|
||||
await page.evaluate(() => document.cookie = `browser-object-default=${encodeURIComponent('{"foo":"foobar"}')}`)
|
||||
await page.getByText('Refresh cookie').click()
|
||||
const text = await page.innerText('pre')
|
||||
text = await page.innerText('pre')
|
||||
expect(text).toContain('foobar')
|
||||
await page.close()
|
||||
})
|
||||
|
8
test/fixtures/basic/pages/cookies.vue
vendored
8
test/fixtures/basic/pages/cookies.vue
vendored
@ -5,7 +5,6 @@ useCookie('set').value = 'set'
|
||||
useCookie('set-to-null').value = null
|
||||
useCookie('set-to-null-with-default', () => 'default').value = null
|
||||
|
||||
const updated = useCookie('updated')
|
||||
// the next set are all sent by browser
|
||||
useCookie('browser-accessed-but-not-used')
|
||||
useCookie('browser-accessed-with-default-value', () => 'default')
|
||||
@ -13,7 +12,8 @@ useCookie('browser-set').value = 'set'
|
||||
useCookie('browser-set-to-null').value = null
|
||||
useCookie('browser-set-to-null-with-default', () => 'default').value = null
|
||||
|
||||
const objectCookie = useCookie('browser-object-default', {
|
||||
const objectCookie = useCookie('browser-object-default')
|
||||
const objectCookieSecond = useCookie('browser-object-default', {
|
||||
default: () => ({ foo: 'bar' })
|
||||
})
|
||||
</script>
|
||||
@ -21,11 +21,11 @@ const objectCookie = useCookie('browser-object-default', {
|
||||
<template>
|
||||
<div>
|
||||
<div>cookies testing page</div>
|
||||
<pre>{{ updated }}</pre>
|
||||
<pre>{{ objectCookieSecond.foo }}</pre>
|
||||
<button @click="objectCookie.foo === 'baz' ? objectCookie.foo = 'bar' : objectCookie.foo = 'baz'">
|
||||
Change cookie
|
||||
</button>
|
||||
<button @click="refreshCookie('updated')">
|
||||
<button @click="refreshCookie('browser-object-default')">
|
||||
Refresh cookie
|
||||
</button>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user