N
Nuxt6mo ago
Mähh

useCookie does share state between layout and component when used in composable

First of all, here is a reproduction: https://stackblitz.com/edit/nuxt-starter-agstq6 It looks like useCookie does not share the state like useState would between vue components. The useCookie is used within a composable and have a simple function to change the state on button click. When i call the state change function from the layout, watch functions in the same layout will trigger. When i call the state change function from another component, the layout is not aware of the changed state of useCookie When i saw correctly, there is a closed issue on github regarding it: https://github.com/nuxt/nuxt/issues/13020 including a PR https://github.com/nuxt/nuxt/pull/20970 from June 23 to fix this. But using Nuxt v3.12.2 this bug appears again.
StackBlitz
Nuxt - Starter (forked) - StackBlitz
Create a new Nuxt project, module, layer or start from a theme with our collection of starters.
GitHub
useCookie state is stored independently · Issue #13020 · nuxt/nuxt
Environment Operating System: Darwin Node Version: v14.17.3 Nuxt Version: 3.0.0 Package Manager: [email protected] Bundler: Vite User Config: - Runtime Modules: - Build Modules: - Reproduction <templat...
GitHub
feat(nuxt): sync useCookie state (including between tabs) by xand...
🔗 Linked issue resolves #13020 ❓ Type of change 📖 Documentation (updates to the documentation, readme or JSdoc annotations) 🐞 Bug fix (a non-breaking change that fixes an issue) 👌 Enhancement...
4 Replies
Reinier Kaper
Reinier Kaper6mo ago
Just for posterity (also posted this on another question): this is still a breaking bug in Nuxt 3.12, you need to downgrade to 3.11 for it to work: https://github.com/nuxt/nuxt/issues/27660
GitHub
Use useCookie to modify the value in one component, but the value i...
Environment Operating System: Windows_NT Node Version: v20.9.0 Nuxt Version: 3.12.2 CLI Version: 3.12.0 Nitro Version: 2.9.6 Package Manager: [email protected] Builder: - Reproduction When running on my d...
Mähh
MähhOP6mo ago
Not tested yet, but saw the comment:
This is related to the now switched-on cookieStore feature. As a workaround, disabling it for now (experimental.cookieStore to false) should resolve the issue.
This is related to the now switched-on cookieStore feature. As a workaround, disabling it for now (experimental.cookieStore to false) should resolve the issue.
Maybe this also works for 3.12 instead downgrading
xibman
xibman6mo ago
@Mähh you have this method to ensure your cookie weel sync : https://nuxt.com/docs/api/utils/refresh-cookie
Nuxt
refreshCookie · Nuxt Utils
Refresh useCookie values manually when a cookie has changed
Reinier Kaper
Reinier Kaper6mo ago
It does not for us We've just been able to get this to work on 3.12.3 by disabling the experimental flag indeed. Might want to do that for now. I believe it's a Chrome(ium?)-only bug
Want results from more Discord servers?
Add your server