N
Nuxt3mo ago
Redeemr

Pinia localstorage Hydration Issues

hey guys, I am currently using pinia and the pinia-plugin-persisted-state plugin to store values from my pinia store. Originally I was using cookies but the size of the store got too large to be stored that way. I switched over to using localstorage and whenever I refresh the page, I get tons of hydration errors because localstorage isnt available on the server. I am able to resolve this by wrapping most of the app in <ClientOnly> but I am wondering what other solutions are there to resolving this problem?
9 Replies
Jacek
Jacek3mo ago
I think it would help a bit if you would share the role of LocalStorage in your project. Does it store primary data (e.g. tasks in a todo app)? shopping cart? profile settings (e.g locale settings, dark mode)? is it cache or the actual data store?
Redeemr
RedeemrOP3mo ago
I am creating a wordle clone so its used to store the users stats, their guesses, the correct answer and stuff like that
Jacek
Jacek3mo ago
And what advantage has SSR over making it fully SPA?
Redeemr
RedeemrOP3mo ago
honestly I'm not sure. I was thinking of that myself and I just assumed since nuxt had so many ssr features enabled that I should be trying to use them
Jacek
Jacek3mo ago
SSR is generally for SEO or content-heavy wikis (if one can utilize nuxt-island's). You can easily appoint specific endpoint to be SSR-ed (like home page or /about) and leave the rest to be SPA. It would eliminate the need for <client-only>
Redeemr
RedeemrOP3mo ago
where do I specify this. I think I saw mention of it earlier while looking through the docs but I dont remember exactly where I saw it
Jacek
Jacek3mo ago
I remember mostly this video
Redeemr
RedeemrOP3mo ago
that worked. Very similiar to the clientOnly approach I was using earlier since I was wrapping parts of the layout in ClientOnly and those parts were the same routes I just setup the rules for. This feels less messy though thanks
Jacek
Jacek3mo ago
Happy to help 🙂 Take care
Want results from more Discord servers?
Add your server