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.

Pinia store values in layout is not server side rendered

See original GitHub issue

Environment

  • Operating System: Darwin
  • Node Version: v16.17.1
  • Nuxt Version: 3.0.0-rc.12
  • Nitro Version: 0.6.0
  • Package Manager: npm@8.15.0
  • Builder: vite
  • User Config: runtimeConfig, meta, modules, image, components, build, css, postcss, vite
  • Runtime Modules: @pinia/nuxt@0.4.3, nuxt-icons@2.0.2, @vueuse/nuxt@9.4.0, @nuxt/image-edge@1.0.0-27769790.4b27db3
  • Build Modules: -

Reproduction

Source code https://github.com/novicell/nuxt3-boilerplate/tree/repro/ssr-layout-hydration

Deployed version https://repro-ssr-layout-hydration--novicell-nuxt3-boilerplate.netlify.app/

Describe the bug

Hi!

We have a general Nuxt 3 boilerplate at Novicell that we use to build various client websites.

We’ve encountered a problem with server side rendering things that is loaded in the layout such as navigation, footer etc.

We use useAsyncData inside our [...slug].vue for rendering CMS pages. To save requests we usually include the navigation in the response on the first page load and set it in our Pinia store which is then loaded inside the layout.

It looks like the layout is rendered before the [...slug].vue and is not hydrated during SSR until the page is loaded.

I’ve made a small example where I have an initial value in the store that is then updated upon fetch of the page.

SSR value Screenshot 2022-11-15 at 08 41 50

Hydrated value Screenshot 2022-11-15 at 08 42 49

I’m not sure if this is a bug or a matter of configuration, but please let us know how to solve it 😄

Additional context

No response

Logs

No response

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
manniLcommented, Nov 15, 2022

AFAIK: If you change store values inside your page components, you cannot alter components “higher up” like the layout or app.vue with it because they are already rendered during SSR (top-down).

But because the client assumes that the new value is propagated everywhere, it will use it for all components. Thus the hydration error.

0reactions
manniLcommented, Nov 15, 2022

Closing here then ☺️

Read more comments on GitHub >

github_iconTop Results From Across the Web

Server Side Rendering (SSR) - Pinia
Creating stores with Pinia should work out of the box for SSR as long as ... client side, we restore the state pinia.state.value...
Read more >
Complex Vue 3 state management made easy with Pinia
Build a basic blog engine using Pinia, a state management tool for Vue apps, and its main features, including state, getters, and actions....
Read more >
is it possible to fill pinia in server-side on nuxt 3? #947 - GitHub
I am trying to replicate the nuxtServerInit() function of Nuxt2 , to start populating data in components once all the data is loaded...
Read more >
vue.js - Nuxt 3 - Pinia Vs useState() - Stack Overflow
1 Answer 1 · A timeline to track actions, mutations · Stores appear in components where they are used · Time travel and...
Read more >
Vue 3 + Pinia - User Registration and Login Example & Tutorial
The alert component renders the alert from the Pinia alert store with bootstrap CSS classes, if the Pinia alert state variable contains a ......
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