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

[nuxt] Feature request: client only storage on some stores only

Open stephenjason89 opened this issue 2 years ago • 3 comments

Describe the bug

I would like to have an option to declare some stores to use localstorage while using my global storage is using cache. I am currently using nuxt and it is registered as a plugin that runs both on server and client.

Changing

 persist: {
                  key: 'user',
                  storage: localStorage,
              },

Causes an error about localstorage not available. And it's the right error because when rendered server side, there's no localstorage available.

So for the meantime I just do, image Usually works but when it doesn't work, it resets to the initial state of the store.

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: 25.35 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
    Safari: 15.4

Used Package Manager

yarn

Validations

stephenjason89 avatar Aug 05 '22 11:08 stephenjason89

Let cache turn into storage-like with unjs/unstorage?

bendwarn avatar Aug 15 '22 07:08 bendwarn

ooooh unstorage seems like a very very interesting option to consider, not only for this issue

prazdevs avatar Aug 15 '22 17:08 prazdevs

It is indeed very interesting. But since it's asynchronous, I'm not really sure how reliable it will be inside plugins and middlewares

stephenjason89 avatar Aug 16 '22 13:08 stephenjason89

v3 is now release with available nuxt module as well! docs are also deployed 🚀 you can use localstorage in some stores and cookies in others :) closing this for now, if still having issues, feel free to reopen

prazdevs avatar Nov 26 '22 01:11 prazdevs