apollo
apollo copied to clipboard
fix: do not destroy $apollo during serverPrefect
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
Solution proposed: Do not destroy $apollo during serverPrefetch lifecycle method.
Then you have a memory leak :D
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?