mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-21 21:25:11 +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) {
|
||||
const channel = typeof BroadcastChannel === 'undefined' ? null : new BroadcastChannel(`nuxt:cookies:${name}`)
|
||||
if (getCurrentScope()) { onScopeDispose(() => { channel?.close() }) }
|
||||
|
||||
const callback = () => {
|
||||
writeClientCookie(name, cookie.value, opts as CookieSerializeOptions)
|
||||
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
|
||||
|
||||
if (getCurrentScope()) {
|
||||
onScopeDispose(() => {
|
||||
watchPaused = true
|
||||
callback()
|
||||
channel?.close()
|
||||
})
|
||||
}
|
||||
|
||||
if (channel) {
|
||||
channel.onmessage = (event) => {
|
||||
watchPaused = true
|
||||
|
Loading…
Reference in New Issue
Block a user