Skip to content

Commit

Permalink
fix: (@vue/apollo-option) memory leak in wrapped ssrRender
Browse files Browse the repository at this point in the history
Fixes #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.
  • Loading branch information
deleteme authored and Akryum committed Aug 14, 2024
1 parent f236070 commit bec7e51
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/vue-apollo-option/src/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
},

Expand Down

0 comments on commit bec7e51

Please sign in to comment.