Closed ClarissaAudrey closed 2 years ago
Hi :)
The type error (persist
does not exist) is due to your types being fetched from src
only. The plugin is imported and installed in renderer/app.ts
so the rest of the app (in src
) never get to know about new options added to defineStore
.
You can add import {} from "pinia-plugin-persistedstate";
in your stores/user.ts
and it will stop yelling at you.
As for the second error, since you are using Server Side Rendering, the error localStorage is not defined
comes from the plugin calling localStorage in a server (node) environment. localStorage
is a browser only API. you may want a different storage (cookies?) or to do the hydration only client side.
I have no idea how vite-plugin-ssr
works, and their documentation isnt helping at all :/
Thank you very much for helping! Your suggestion works, i really appreciated the answer.
regarding the localStorage
bit, i think your explanation makes a lot sense. I am gonna try and figure out how to configure this on vite-plugin-ssr
.
Once again, thank you very much for your assistance!
I have the same problem with vite-plugin-ssr
@ClarissaAudrey, can you find a way to use pinia-plugin-persistedstate
with ite-plugin-ssr
to store data in localstorage which is fetched in serverside?
@ClarissaAudrey No problem hopefully that solves most of your problems or gives you hints to solve them. Feel free to close the issue if you're fine with the answer 👍
@hamedg68
I have the same problem with vite-plugin-ssr @ClarissaAudrey, can you find a way to use
pinia-plugin-persistedstate
withite-plugin-ssr
to store data in localstorage which is fetched in serverside?
localStorage
is a client API, it can never be used/accessed server side. I recommend you use some other things such as cookies. But I have no clue how vite-plugin-ssr
works, and the docs are really putting me off it :/
Hi @hamedg68 , I have came up with a solution, not sure if it is applicable to you, so what i did is i render the localStorage
only on the client side. Or you can try the cookie option that @prazdevs suggested.
Describe the bug
Hi! so i am having several issues regarding implementing the pinia-persisted-state.
Environment: vue3.2.39+pinia2.0.22+pinia-plugin-persistedstate2.2.0+vite3.0.9+vite-plugin-ssr0.4.38
code
first issue:
I can't really seem to import
persist:true
, this is the issue that i'm havingsecond issue: Upon compiling the app, this is the error that occurs:
can you help me fix this issue?
Thanks beforehand!
Reproduction
https://github.com/ClarissaAudrey/pinia-persisted-issue
System Info
Used Package Manager
npm
Validations