Skip to content

Can Not Re-assign $apollo #924

@RedPlatypus

Description

@RedPlatypus

Describe the bug
Multiple web-components on a page implementing vue-apollo 3.0.3. lead to re-definition error of $apollo

To Reproduce
Steps to reproduce the behavior:

  1. Build 2 vue components seperatly that both implement vue-apollo using whatever your bundler is. We're using https://cli.vuejs.org/guide/cli-service.html#vue-cli-service-build Vue-Cli-Service
  2. Import both of these web-components into a new page
  3. See error

Uncaught TypeError: Cannot redefine property: $apollo

Expected behavior

  1. This error would not occur
  2. vue-apollo would check if it's redefining $apollo
  3. In packages>vue-apollo>src>index.js the Apollo package would wrap define in a check to see if $apollo is already defined.
  // Lazy creation
  if (!Vue.prototype.hasOwnProperty('$apollo')) {
    Object.defineProperty(Vue.prototype, '$apollo', {
      get () {
        if (!this.$_apollo) {
          this.$_apollo = new DollarApollo(this)
        }
        return this.$_apollo
      },
    })
  }

Versions
vue: "^2.6.11"
vue-apollo: 3.0.3
apollo-client: "^2.6.4"

Additional context
Seems that this was a past issue, and had been resolved, and then removed?
#358

66b8cc9#diff-6c29e3b5395a867dff4aa2f0dc7124b2

I would have added a PR, but could not figure out how to build dist files.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions