pinia-plugin-persistedstate icon indicating copy to clipboard operation
pinia-plugin-persistedstate copied to clipboard

[nuxt] calling store.$hydrate uses old values

Open stephenjason89 opened this issue 3 years ago • 0 comments

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.

image

As you can see,

  1. I updated the auth store with auth.refresh()
  2. I console.log the tokenExpiration before and after auth.refresh()
  3. 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. image

This was logged from my pinia plugin createPersistedState image

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

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

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

stephenjason89 avatar Aug 05 '22 18:08 stephenjason89