[nuxt] createNuxtPersistedState SSR states empty (not working)
See original GitHub issueDescribe the bug
The states are only restored from cookie at the client side. Anything that is rendered on server side like, any code that runs on created hook or earlier doesn’t have the states available You can see it if you console.log it. This means, middleware and plugins store will return an empty state on page load as well.
Reproduction
Install @pinia/nuxt 0.2.0 together with pinia 2.0.15 Tested with pinia-plugin-persisted: 1.6.3 and 2.1.0 with 2.1.0 i get the following error
System Info
System:
OS: macOS 12.3
CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Memory: 20.51 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
- Follow our Code of Conduct
- Read the Contributing Guide.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- The provided reproduction is a minimal reproducible of the bug.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:12 (5 by maintainers)
Top Results From Across the Web
Nuxt3 + Pinia + VueUse -> useStorage() not working
I found an answer to this: Nuxt3 uses SSR by default. But since useStorage() (from VueUse) uses the browsers localstorage this can't work....
Read more >SSR: How to protect oneself from empty objects #2632 - GitHub
I have an object passed down with a prop from a page component to a regular component. Sometimes the object is undefined (depending...
Read more >Installation - Nuxt
The next step is to navigate to the project folder and launch it: ... Create an empty directory with the name of your...
Read more >Creating Server-side Rendered Vue.js Apps Using Nuxt.js
Nuxt.js is based off an implementation of SSR for the popular React ... There is a problem: We see the original state for...
Read more >Server Side Rendering (SSR) - Pinia
If you are using Nuxt.js, you need to read these instructions instead. Creating stores with Pinia should work out of the box for...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@prazdevs I understand where you’re coming from. The only problem is that useCookie by nuxt doesn’t work properly across server to client cookie management.
This only works properly on client only setup.
If you see my PR, it doesn’t require a certain package to be used
Any package that follows the .get() and .set() are welcome
You can even use js-cookie library
But again, problem on serverside cookie get and set will arise.
The get part on server can be solved with parsing the cookie in req headers. The setting part is a bit trickier.
cookie-universal solves this easily
v3 is now release with available nuxt module as well! docs are also deployed 🚀 closing this for now, if still having issues, feel free to reopen