question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[nuxt] createNuxtPersistedState SSR states empty (not working)

See original GitHub issue

Describe 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 image image

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
stephenjason89commented, Aug 5, 2022

@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

0reactions
prazdevscommented, Nov 26, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found