apollo icon indicating copy to clipboard operation
apollo copied to clipboard

fix: do not manually call provide

Open souldzin opened this issue 4 years ago • 1 comments

Context

Over at GitLab, we ran into a weird quirk with VueApollo (see relevant GitLab comment).

Here's a sandbox example of the issue we ran into:

// 1) Somewhere we use VueApollo
Vue.use(VueApollo);

// 2) Elsewhere, we initialize a top-level Vue app that **does not** give `apolloProvider`
import Root from './root.vue';

new Vue({
  el,
  render(h) {
    return h(Root, {
      props: { 
        username: 'sam'
      } 
    }; 
  },
})

// root.vue
export default {
  provide() {
    // 3) This blows up because VueApollo manually calls `provide` on `beforeCreate`.
    // Vue will usually call this **after** props and things have been set up.
    return {
      username: this.username
    };
  },
  props: {
    username: {
      type: String,
      required: true,
    },
  }, 
}

It looks like this manual calling of options.provide was to support an old VueApollo API, but since Vue 2.2.0, Vue automatically supports provide. I'm guessing this isn't needed anymore :shrug:

souldzin avatar Feb 23 '21 14:02 souldzin

@Akryum could you review this small PR that removes some code tagged TODO remove? Thank you! :bow:

souldzin avatar Feb 23 '21 14:02 souldzin

Hi @Akryum, any update on this? Could it be merged? 🙂

I just came across another case in a GitLab vue component where this causes an issue.

lorenzvanherwaarden avatar Sep 11 '23 14:09 lorenzvanherwaarden