michaelolof / vuex-class-component

A Type Safe Vuex Module or Store Using ES6 Classes and ES7 Decorators written in TypeScript.
217 stars 21 forks source link

[Bug] SSR data not saved in store when using nuxt fetch hook #82

Open ghost opened 4 years ago

ghost commented 4 years ago

Hello !

I ran into an issue while using this library. I am using version 2.3.5.

When using nuxt fetch hook, and dispatching an action in the store, the data stored in the state vanishes once the page is loaded. However, when using the asyncData hook allows you to have your component data reflecting the ssr fetched state. But if in that same hook you only call the action (i.e. don't return anything), the problem is the same as with fetch.

I have created a reproduction repo there : https://github.com/Ghalnas/vuex-class-component-test

Thanks in advance !

marijngiesen commented 3 years ago

I'm having the same issue. The store doesn't seem to get hydrated with SSR data.

navFooh commented 3 years ago

Here as well. I'm using the fetch() method of a layout to call an async function on the store for retrieving data. This works well on the server-side, the page is being served with the right data.

However, after a split second, the store is initialized on the client side and the data disappears.

aurror commented 2 years ago

Hey, same here.

I created a reproduction scenario, showing that it works with asyncData, but not with fetch. Using fetch, the warning "Cannot stringify a function" appears several times, and the site is broken.