Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

feat(vue 3): migrate from Vue.default.version to a fallback #847

Merged
merged 5 commits into from
Jun 1, 2021

Conversation

Haroenv
Copy link
Contributor

@Haroenv Haroenv commented Sep 4, 2020

In Vue 3 version is an explicit export, while in Vue 2 it's a property of the default export.

This way does give a warning ⚠️ when using Vue 2: "export 'version' (imported as 'A') was not found in 'vue'. I'm not too sure how to avoid that

see: https://v3.vuejs.org/guide/migration/global-api-treeshaking.html

In Vue 3 `version` is an explicit export, while in Vue 2 it's a property of the default export.

This way _does_ give a warning ⚠️ when using Vue 2: `"export 'version' (imported as 'A') was not found in 'vue'`. I'm not too sure how to avoid that
@Haroenv Haroenv added this to the Vue 3 milestone Sep 4, 2020
anton-rob added a commit to anton-rob/vue-instantsearch that referenced this pull request Feb 22, 2021
@eunjae-lee
Copy link
Contributor

When this file is transpiled, it becomes

import Vue__default, { version } from 'vue';

In Vue 3, there is no default export. So we get errors like this:

 > node_modules/vue-instantsearch/es/src/util/createInstantSearchComponent.js:4:7: error: No matching export in "node_modules/vue/dist/vue.runtime.esm-bundler.js" for import "default"
    4 │ import Vue__default, { version } from 'vue';
      ╵        ~~~~~~~~~~~~

Not sure how to fix it yet.

@Kocal
Copy link
Contributor

Kocal commented Apr 9, 2021

I think it would be great to use vue-demi which provide compatibility layers between Vue 2 and 3 for plugins, something like this:

import { isVue2, isVue3 } from 'vue-demi'

// ...

searchClient.addAlgoliaAgent(
  `Vue (${isVue2() ? 2 : 3 })`
);

@Haroenv
Copy link
Contributor Author

Haroenv commented Apr 12, 2021

That could be interesting, but the real version we are looking for there is 2.x.x / 3.x.x to better gauge how far we should continue to support. Thanks for your input though @Kocal, maybe a dynamic import at that point could work?

@Kocal
Copy link
Contributor

Kocal commented Apr 12, 2021

Yeah, I suppose you can do something like this which seems to work for Vue 2 and Vue 3:

searchClient.addAlgoliaAgent(
  `Vue (${require('vue').version})`
);

@eunjae-lee
Copy link
Contributor

function getVueVersion() {
  if (typeof window !== 'undefined' && typeof window.Vue !== 'undefined') {
    return window.Vue.version; // for umd
  } else {
    return require('vue').version;
  }
}

What do you think?

@Kocal
Copy link
Contributor

Kocal commented Apr 12, 2021

That's even better! 😄

@Haroenv
Copy link
Contributor Author

Haroenv commented Apr 12, 2021

are you sure mixing require/import will not cause issues in other platforms / bundlers?

@eunjae-lee
Copy link
Contributor

are you sure mixing require/import will not cause issues in other platforms / bundlers?

nope, not at all 😅
I think at a little later phase, we need to run it on major platforms / bundlers to see if everything works fine.

@eunjae-lee eunjae-lee changed the base branch from master to feat/vue3-compat April 13, 2021 12:00
@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 13, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 74272f3:

Sandbox Source
vue-instantsearch-e-commerce Configuration

@Kocal Kocal mentioned this pull request May 21, 2021
@eunjae-lee
Copy link
Contributor

Apparently, in one of my sandboxes, I'm seeing an issue with (probably) this require. I'm adding vue-demi in this PR to see if it works.

@eunjae-lee eunjae-lee force-pushed the feat/v3-compat-version branch 3 times, most recently from 3341e04 to 3c41c80 Compare June 1, 2021 09:39
@eunjae-lee eunjae-lee force-pushed the feat/v3-compat-version branch from 3c41c80 to 74272f3 Compare June 1, 2021 12:11
@eunjae-lee eunjae-lee marked this pull request as ready for review June 1, 2021 12:36
@eunjae-lee eunjae-lee merged commit 247260e into feat/vue3-compat Jun 1, 2021
@eunjae-lee eunjae-lee deleted the feat/v3-compat-version branch June 1, 2021 12:38
Haroenv added a commit to algolia/instantsearch that referenced this pull request Dec 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants