apollo icon indicating copy to clipboard operation
apollo copied to clipboard

fix: do not destroy $apollo during serverPrefect

Open art-boer opened this issue 3 years ago • 2 comments

Fixes: https://github.com/vuejs/apollo/issues/1297

Package: Apollo Option

Situation: $apollo gets destroyed during serverPrefetch, this triggers server errors in components that use $apollo.

Solution proposed: Do not destroy $apollo during serverPrefetch lifecycle method.

Code sandbox showing the error: https://codesandbox.io/s/nuxt-3-ssr-apollo-option-srw1jw?file=/pages/index.vue

art-boer avatar Jul 18 '22 07:07 art-boer

Solution proposed: Do not destroy $apollo during serverPrefetch lifecycle method.

Then you have a memory leak :D

Akryum avatar Jul 18 '22 08:07 Akryum

I am still learning Vue so please correct me if I am wrong.

I am not 100% sure what the lifecycle flow is of serverPrefetch, couldn't find too much information on it in the Vue docs. However, looking at the following file: https://github.com/vuejs/core/blob/main/packages/server-renderer/src/render.ts it seems like the rendering of VNodes happens after running serverPrefetch has been handled, meaning that the server-side component rendering should break if it comes across a v-if="$apollo...".

Are there any other possible solutions to be able to use $apollo?

art-boer avatar Jul 18 '22 09:07 art-boer