diff --git a/packages/nuxt/src/app/composables/cookie.ts b/packages/nuxt/src/app/composables/cookie.ts index be64a70364..09015f8544 100644 --- a/packages/nuxt/src/app/composables/cookie.ts +++ b/packages/nuxt/src/app/composables/cookie.ts @@ -69,7 +69,7 @@ export function useCookie (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 }) => { diff --git a/test/basic.test.ts b/test/basic.test.ts index 225af98542..abaa830c4e 100644 --- a/test/basic.test.ts +++ b/test/basic.test.ts @@ -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() }) diff --git a/test/fixtures/basic/pages/cookies.vue b/test/fixtures/basic/pages/cookies.vue index b4d2dfb67a..7a0c2ffb12 100644 --- a/test/fixtures/basic/pages/cookies.vue +++ b/test/fixtures/basic/pages/cookies.vue @@ -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' }) }) @@ -21,11 +21,11 @@ const objectCookie = useCookie('browser-object-default', {