mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-19 01:45:53 +00:00
fix(nuxt): handle failure creating BroadcastChannel (#26340)
This commit is contained in:
parent
9b9558bcf9
commit
2c0fc3a15e
@ -63,7 +63,15 @@ export function useCookie<T = string | null | undefined> (name: string, _opts?:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (import.meta.client) {
|
if (import.meta.client) {
|
||||||
const channel = store || typeof BroadcastChannel === 'undefined' ? null : new BroadcastChannel(`nuxt:cookies:${name}`)
|
let channel: null | BroadcastChannel = null
|
||||||
|
try {
|
||||||
|
if (!store && typeof BroadcastChannel !== 'undefined') {
|
||||||
|
channel = new BroadcastChannel(`nuxt:cookies:${name}`)
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// BroadcastChannel will fail in certain situations when cookies are disabled
|
||||||
|
// or running in an iframe: see https://github.com/nuxt/nuxt/issues/26338
|
||||||
|
}
|
||||||
const callback = () => {
|
const callback = () => {
|
||||||
if (opts.readonly || isEqual(cookie.value, cookies[name])) { return }
|
if (opts.readonly || isEqual(cookie.value, cookies[name])) { return }
|
||||||
writeClientCookie(name, cookie.value, opts as CookieSerializeOptions)
|
writeClientCookie(name, cookie.value, opts as CookieSerializeOptions)
|
||||||
|
Loading…
Reference in New Issue
Block a user