mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(nuxt): clear cookie BroadcastChannel when scope is disposed (#23664)
This commit is contained in:
parent
1d43cdc908
commit
5c7cca170a
@ -1,5 +1,5 @@
|
||||
import type { Ref } from 'vue'
|
||||
import { getCurrentInstance, nextTick, onUnmounted, ref, watch } from 'vue'
|
||||
import { getCurrentScope, nextTick, onScopeDispose, ref, watch } from 'vue'
|
||||
import type { CookieParseOptions, CookieSerializeOptions } from 'cookie-es'
|
||||
import { parse, serialize } from 'cookie-es'
|
||||
import { deleteCookie, getCookie, getRequestHeader, setCookie } from 'h3'
|
||||
@ -35,7 +35,7 @@ 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 (getCurrentInstance()) { onUnmounted(() => { channel?.close() }) }
|
||||
if (getCurrentScope()) { onScopeDispose(() => { channel?.close() }) }
|
||||
|
||||
const callback = () => {
|
||||
writeClientCookie(name, cookie.value, opts as CookieSerializeOptions)
|
||||
|
Loading…
Reference in New Issue
Block a user