Skip to content

Commit 98bc132

Browse files
authored
fix: Cannot Re-assign $apollo, closes #924 (#930)
* 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...
1 parent ad54260 commit 98bc132

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

packages/vue-apollo/src/index.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,16 @@ export function install (Vue, options) {
3838
}
3939

4040
// Lazy creation
41-
Object.defineProperty(Vue.prototype, '$apollo', {
42-
get () {
43-
if (!this.$_apollo) {
44-
this.$_apollo = new DollarApollo(this)
45-
}
46-
return this.$_apollo
47-
},
48-
})
41+
if (!Vue.prototype.hasOwnProperty('$apollo')) {
42+
Object.defineProperty(Vue.prototype, '$apollo', {
43+
get () {
44+
if (!this.$_apollo) {
45+
this.$_apollo = new DollarApollo(this)
46+
}
47+
return this.$_apollo
48+
},
49+
})
50+
}
4951

5052
installMixin(Vue, vueVersion)
5153

0 commit comments

Comments
 (0)