pinia-plugin-persistedstate does not update cookies and localStorage in Nuxt 3 (Prod, SSR) #386
Open
5 tasks done
Labels
🔍️ pending triage
This issue needs to be looked into
Are you using Nuxt?
Describe the bug
I am using pinia-plugin-persistedstate in a Nuxt 3 project to persist state in cookies. In dev mode, everything works fine, but in production (SSR), the cookies do not update, even though the Pinia state changes.
❗ Additionally:
If I change storage: 'localStorage', data does not get stored in localStorage in production, even though console.log shows the updated state.
Expected behavior
After updating the Pinia state:
In DevTools → Application → Storage → Cookies, the cookie value should be updated.
In DevTools → Application → Storage → LocalStorage, the stored data should be updated.
Steps to reproduce
Install pinia-plugin-persistedstate in Nuxt 3 (npm i pinia-plugin-persistedstate).
Configure persist in nuxt.config.ts:
Create a Pinia store:
Run the app in prod mode:
npm run build && npm run start
Change the state (setCurrentCompany) and check Cookies/LocalStorage.
Actual behavior
In dev mode: Everything works → document.cookie and localStorage update correctly.
In prod mode: console.log confirms state changes, but Cookies and LocalStorage do not update.
What I have tried
✅ Manually updating cookies using useCookie() – works.
✅ Clearing old cookies before updating – does not help.
✅ Forcing $patch() in Pinia – does not help.
✅ Disabling persist in SSR (persist: process.client ? true : false) – does not help.
Versions
nuxt: 3.15.4
@pinia/nuxt: 0.10.1
pinia-plugin-persistedstate: 4.2.0
node.js: 20.15.1
Additional Information
SSR is enabled (ssr: true).
Cookies only update if manually set using useCookie().
No console errors, but cookies and localStorage do not update in production.
Question
🔹 Is this a bug in pinia-plugin-persistedstate, or am I missing something?
🔹 Why does useCookie() work, but persistedstate does not?
Any help would be greatly appreciated!
Reproduction
The issue only occurs after running npm run build && npm run start, making it impossible to reproduce in an online playground like StackBlitz
System Info
Used Package Manager
yarn
Validations
The text was updated successfully, but these errors were encountered: