mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 15:15:19 +00:00
fix(nuxt): write cookie values before navigating away (#23697)
This commit is contained in:
parent
24b629e82e
commit
34adac661d
@ -35,8 +35,6 @@ export function useCookie<T = string | null | undefined> (name: string, _opts?:
|
|||||||
|
|
||||||
if (import.meta.client) {
|
if (import.meta.client) {
|
||||||
const channel = typeof BroadcastChannel === 'undefined' ? null : new BroadcastChannel(`nuxt:cookies:${name}`)
|
const channel = typeof BroadcastChannel === 'undefined' ? null : new BroadcastChannel(`nuxt:cookies:${name}`)
|
||||||
if (getCurrentScope()) { onScopeDispose(() => { channel?.close() }) }
|
|
||||||
|
|
||||||
const callback = () => {
|
const callback = () => {
|
||||||
writeClientCookie(name, cookie.value, opts as CookieSerializeOptions)
|
writeClientCookie(name, cookie.value, opts as CookieSerializeOptions)
|
||||||
channel?.postMessage(opts.encode(cookie.value as T))
|
channel?.postMessage(opts.encode(cookie.value as T))
|
||||||
@ -44,6 +42,14 @@ export function useCookie<T = string | null | undefined> (name: string, _opts?:
|
|||||||
|
|
||||||
let watchPaused = false
|
let watchPaused = false
|
||||||
|
|
||||||
|
if (getCurrentScope()) {
|
||||||
|
onScopeDispose(() => {
|
||||||
|
watchPaused = true
|
||||||
|
callback()
|
||||||
|
channel?.close()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if (channel) {
|
if (channel) {
|
||||||
channel.onmessage = (event) => {
|
channel.onmessage = (event) => {
|
||||||
watchPaused = true
|
watchPaused = true
|
||||||
|
Loading…
Reference in New Issue
Block a user