pinia-plugin-persistedstate
pinia-plugin-persistedstate copied to clipboard
[nuxt] calling store.$hydrate uses old values
Describe the bug
Note: this bug is only during SSR
After calling store.$hydrate() Store was hydrated with old values and not the new ones.
As you can see,
- I updated the auth store with auth.refresh()
- I console.log the tokenExpiration before and after auth.refresh()
- I called auth.$hydrate() to update the store
See the error: Clearly after method auth.refresh() was called, a new tokenExpiration is logged.
But after calling the $hydrate, it still uses the old one.

This was logged from my pinia plugin createPersistedState

I was changing the state like this & setItem is not being called automatically in SSR so i had to do $hydrate

However, setting the store like this, seems to work fine in SSR and setItem is being called with correct values

Reproduction
Install @pinia/nuxt 0.3.1 together with pinia 2.0.17
System Info
System:
OS: macOS 12.3
CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Memory: 29.00 GB / 64.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 18.7.0 - /usr/local/bin/node
Yarn: 3.2.1 - /usr/local/bin/yarn
npm: 8.15.0 - /usr/local/bin/npm
Browsers:
Chrome: 104.0.5112.79
Firefox: 103.0
Used Package Manager
yarn
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guide.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] The provided reproduction is a minimal reproducible of the bug.