vuejs / pinia

🍍 Intuitive, type safe, light and flexible Store for Vue using the composition api with DevTools support
https://pinia.vuejs.org
MIT License
12.91k stars 1.02k forks source link

Caching getters on server with Nuxt2 is not working as expected #2529

Open yoshrubin opened 8 months ago

yoshrubin commented 8 months ago

Reproduction

https://github.com/yoshrubin/pinia-ssr-bug

Steps to reproduce the bug

  1. run yarn build && yarn start

Expected behavior

To return a cached version of the getter

Actual behavior

the getter was called for each loop in the v-for loop instead of returning a cached version

Additional information

The issue is for Nuxt2 with@pinia/nuxt@0.2.1 which uses pinia@^2.1.7

yoshrubin commented 8 months ago

@posva Hey thanks for adding labels, from what I can tell this appears to be an issue with nuxt-bridge as well which will be an issue for anyone trying to make the move from Nuxt2 to Nuxt3. Happy to provide a repro for that as well if it will help narrow down the source of this issue.

yoshrubin commented 8 months ago

it appears that the issue is here packages/pinia/src/store.ts#L179C19-L179C19 the computed is getting re-evaluated multiple times even though the dependencies aren't changing.

I did come across this discussion that I am unsure if it is relevant or not https://github.com/vuejs/pinia/discussions/1020 and he references

ssr: make computed inactive during ssr, fix memory leak (f4f0966), closes #5208

from the vue 3.2.27 CHANGELOG

yoshrubin commented 8 months ago

@posva seems like the "issue" I mention here is actually the intended functionality based on responses to https://github.com/vuejs/vue/issues/10151 and https://github.com/nuxt/nuxt/issues/2447. Wish there was a better solution or more documentation for this kind of issue (maybe a mention in the SSR section of the Docs). Happy to contribute to the docs myself when I clear some time for it.