From 1e54b676787b93f3e49628bcf1a6e78d1c2b0052 Mon Sep 17 00:00:00 2001 From: Matt Garrett Date: Wed, 8 May 2024 17:33:16 -0700 Subject: [PATCH] fix: (@vue/apollo-option) memory leak in wrapped ssrRender Fixes https://github.com/vuejs/apollo/issues/1550 Two leaks were fixed: 1) Prevents repeatedly wrapping `ssrRender` by checking if it's already been wrapped. Added a `__IS_VUE_APOLLO_WRAPPED` boolean to track this. I verified that this was actually happening by throwing an error if it was already wrapped, and I observed the error. 2) `this.$options.ssrRender` doesn't always exist, but this.$apollo does. When the new wrapped `ssrRender` was called, it would throw, which prevented the `destroy.call(this)` line from running. The fix here was to not create a wrapped `ssrRender` if there isn't an original one. --- packages/vue-apollo-option/src/mixin.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/vue-apollo-option/src/mixin.js b/packages/vue-apollo-option/src/mixin.js index a2ecc8aa..02555158 100644 --- a/packages/vue-apollo-option/src/mixin.js +++ b/packages/vue-apollo-option/src/mixin.js @@ -115,11 +115,14 @@ export function installMixin (app, provider) { if (isServer) { // Patch render function to cleanup apollo const render = this.$options.ssrRender + if (!render) return + if (render.__IS_VUE_APOLLO_WRAPPED) return this.$options.ssrRender = (h) => { const result = render.call(this, h) destroy.call(this) return result } + this.$options.ssrRender.__IS_VUE_APOLLO_WRAPPED = true } },