Skip to content

Commit

Permalink
fix: Cannot Re-assign $apollo, closes #924 (#930)
Browse files Browse the repository at this point in the history
* Fix for Issue #924 (Cannot Re-assign $apollo)

#924

Added the recommended sanity check .hasOwnProperty that is best practice for .defineProperty to fix .$apollo redefinition bug when using more than one Vue application on a page, or multiple vue built standard web components, like a web component library.

This bug is a show stopper for using vue-apollo in standard web components but fortunately was easily fixable by adding the standard best practices check around the block to prevent redefinition.

Also worth noting that this same issue it has occurred and crept back into this project several times.

* Update: Adjusted indentation to pass project checks...

Update: Adjusted indentation to pass project checks...
  • Loading branch information
JoshuaJarman authored Jul 27, 2020
1 parent ad54260 commit 98bc132
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/vue-apollo/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ export function install (Vue, options) {
}

// Lazy creation
Object.defineProperty(Vue.prototype, '$apollo', {
get () {
if (!this.$_apollo) {
this.$_apollo = new DollarApollo(this)
}
return this.$_apollo
},
})
if (!Vue.prototype.hasOwnProperty('$apollo')) {
Object.defineProperty(Vue.prototype, '$apollo', {
get () {
if (!this.$_apollo) {
this.$_apollo = new DollarApollo(this)
}
return this.$_apollo
},
})
}

installMixin(Vue, vueVersion)

Expand Down

0 comments on commit 98bc132

Please sign in to comment.