New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(nuxt): sync useCookie
state (including between tabs)
#20970
Conversation
β Live Preview ready!
|
β¦nuxt into fix/shared-cookie-state
Updated it to use BroadcastChannel API. Now it is synced across tabs and we don't need new Nuxt events. |
@danielroe can you please take a look and review, thx |
@xanderbarkhatov thx well done... @danielroe can you please review? |
@c-schwan You do not need to ping me to review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
β€οΈ
@@ -34,9 +34,28 @@ export function useCookie<T = string | null | undefined> (name: string, _opts?: | |||
const cookie = ref<T | undefined>(cookies[name] as any ?? opts.default?.()) | |||
|
|||
if (process.client) { | |||
const callback = () => { writeClientCookie(name, cookie.value, opts as CookieSerializeOptions) } | |||
const channel = new BroadcastChannel(`nuxt:cookies:${name}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, there is small percentage of browsers not supporting this API, i would add a check guard if feature is not available.
useCookie
stateuseCookie
state between tabs
Um, and how it resolved issues when two components in same tab use |
They are synced even within the same tab. |
I guess your title is a little bit confusing) |
useCookie
state between tabsuseCookie
state (including between tabs)
π Linked issue
resolves #13020
β Type of change
π Description
Use BroadcastChannel API to sync state across
useCookie
invocationsπ Checklist