Skip to content

Weird behavior with SSR #948

Jan 6, 2022 · 2 comments · 10 replies
Discussion options

You must be logged in to vote

Now I see the problem: on the client side you need to make sure you hydrate the state before using the store:

    const pinia = createPinia()

    app.use(pinia)

    // This does not work
    if (import.meta.env.SSR) {
      doSomethingWithStore()
      const store = useStore()
      store.fetchSomething()
      initialState.pinia = pinia.state.value
    } else {
      pinia.state.value = initialState.pinia
      doSomethingWithStore()
    }

On server you finish by serializing the state to the client while on the client you start by reading (hydrating) the state before using the store.

Replies: 2 comments 10 replies

Comment options

You must be logged in to vote
8 replies
@posva
Comment options

@thierrymichel
Comment options

@posva
Comment options

@thierrymichel
Comment options

@posva
Comment options

Comment options

You must be logged in to vote
2 replies
@thierrymichel
Comment options

@posva
Comment options

Answer selected by posva
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #941 on January 11, 2022 08:39.