universal-vue / uvue

Vue CLI plugin to create universal Vue applications with ease
https://universal-vue.github.io/docs/
MIT License
127 stars 13 forks source link

serverCacheKey does not work correctly with apollo #40

Closed academici closed 4 years ago

academici commented 4 years ago

Describe the bug If using serverCacheKey parameter in component, __APOLLO_STATE__ does not contain query data.

To Reproduce Create any component with apollo query and serverCacheKey parameter.

Please indicate versions of:

node: 12.11
vue-cli: 4.0.0-rc.7
uvue: 0.1.0-alpha.19
os: ubuntu 18.04
browser: chrome 77
yabab-dev commented 4 years ago

Can you provide a repo for this ? I'm unable to reproduce it

academici commented 4 years ago

repo When you first visit the page APOLLO_STATE contain server data After pefresh page APOLLO_STATE is empty.

yabab-dev commented 4 years ago

Without your graphql server I can't test it

yabab-dev commented 4 years ago

Hi @academici,

I've run some tests on others SSR solutions for Vue: I am able to reproduce this issue with Nuxt and Akryum plugin.

Indeed, this is not a bug but a normal behavior, here is the flow:

  1. On first rendering, component and its hooks are called normally
  2. If the component has serverCachekey function defined, the Vue renderer cache the final HTML
  3. On second rendering, Vue renderer simply return the cached HTML without calling any component hooks (like the serverPrefetch hook)

So, in this case, apollo plugin is not called during the component rendering, and then apollo state is empty!