Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Issue #924 (Cannot Re-assign $apollo) #930

Merged
merged 2 commits into from
Jul 27, 2020
Merged

Conversation

JoshuaJarman
Copy link

#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 it appears this same issue it has occurred and crept back into this project several times.

vuejs#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...
@spinningarrow
Copy link

Would love for this to be merged in! Currently having issues because VueApollo insists on being installed globally if Vue is exposed globally…

@gkweb
Copy link

gkweb commented Apr 28, 2020

Please merge this in - Having this exact same issue with a global Vue declared.

@gkweb
Copy link

gkweb commented Apr 28, 2020

Temporary solution

For anyone else having this issue - Declare your Vue anything but window.Vue. I have a simple resolver function to resolve to the window object. Can be updated for SSR if need be global || window. See below:

/** Resolves the global window Vue */
export const resolveVue = () => {
  if (window && !window.__Vue) {
    window.__Vue = Vue
  }	
  return window.__Vue
}

const GlobalVue = resolveVue()

And then you can use VueApollo and check for its existence manually on the object already if need be

if (!Object.prototype.hasOwnProperty.call(GlobalVue, '$apollo')) {
  GlobalVue.use(VueApollo)
}

This is definitely an edge case but I hope this helps

@jpagarcia
Copy link

jpagarcia commented May 18, 2020

Any update on this? Would like to get this working on NuxtJS. I've tried the changes made and it does work.

@Akryum Akryum merged commit 98bc132 into vuejs:dev Jul 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants