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

feat(compat): add Vue 3 support via @vue/compat (fixes #5196) #6845

Closed
wants to merge 29 commits into from

Conversation

xanf
Copy link
Member

@xanf xanf commented Nov 20, 2021

image

❓ What is it?

Version of Bootstrap-Vue which works for Vue 2 and Vue 3 (using @vue/compat)
Helps people with #5196

Demo using Vue 2
Demo using Vue 3

Additionally, it passes all (well, almost all, tiny fraction of tests are disabled because they are irrelevant for vue 3) tests in the test suite (it would be literally impossible to do this migration without a test suite)

This package uses vue 3 by default. If you want to run tests, build, etc. using vue 2 pass USE_VUE2=1 environment variable

❗ How is this possible?

The heart of this PR consists of two parts:

🔧 How could I run it?

If you want just to play around - you can clone https://github.com/xanf/bootstrap-vue3-demo which has all required setup. If you want to try it on your own project, there is some setup required.

I'm skipping setup of @vue/compat, it is described in migration guide

You will need to monkey patch your Vue 3 a bit somewhere early in your app:

  const originalVModelDynamicCreated = Vue.vModelDynamic.created;
  const originalVModelDynamicBeforeUpdate = Vue.vModelDynamic.beforeUpdate;
  Vue.vModelDynamic.created = function (el, binding, vnode) {
    originalVModelDynamicCreated.call(this, el, binding, vnode);
    if (!el._assign) {
      el._assign = () => {};
    }
  };
  Vue.vModelDynamic.beforeUpdate = function (el, binding, vnode) {
    originalVModelDynamicBeforeUpdate.call(this, el, binding, vnode);
    if (!el._assign) {
      el._assign = () => {};
    }
  };

See vuejs/core#4121 for details

If your intention is to run your app in { MODE: 2 } (default @vue/compat) you're done.
If you want to have { MODE: 3 } (so all compats are disabled by default), additional setup is needed:

If you use portal-vue (which is still used for tooltips, etc.) you will need:

  • GLOBAL_SET

If you use old (for Vue 2) version of vue-router you will need:

  • CONFIG_OPTION_MERGE_STRATS
  • GLOBAL_PRIVATE_UTIL
  • GLOBAL_PROTOTYPE
  • INSTANCE_EVENT_HOOKS
  • OPTIONS_DESTROYED
  • INSTANCE_EVENT_EMITTER

💣 What might not work

  • Docs. I've tried to make Nuxt run using newer Nuxt 3, bridge, etc. but it was very problematic. So I wrote a script, which extracted demos from docs and generated https://github.com/xanf/bootstrap-vue3-demo with all demos
  • Build. It might or might not work, I didn't have an opportunity to test it yet

↗️ What's next?

Let's treat this one as "bridge" version
Based on this branch I will create another one, which will be focused solely on full vue 3 compatibility (without using @vue/compat). While this will definitely take time, right now I do not see any major obstacles in gradual migration

🤗 That's cool, how could I say "thank you"?

You're welcome, it's all about opensource. However, there are certain things, where your help will be appreciated:

PR checklist

What kind of change does this PR introduce? (check at least one)

  • Bugfix (fixes a boo-boo in the code) - fix(...), requires a patch version update
  • Feature (adds a new feature to BootstrapVue) - feat(...), requires a minor version update
  • Enhancement (augments an existing feature) - feat(...), requires a minor version update
  • ARIA accessibility (fixes or improves ARIA accessibility) - fix(...), requires a patch or minor version update
  • Documentation update (improves documentation or typo fixes) - chore(docs), requires a patch version update
  • Other: major update

Does this PR introduce a breaking change? (check one)

  • No (I know it's hard to believe)
  • Yes (please describe since breaking changes require a minor version update)

The PR fulfills these requirements:

  • It's submitted to the dev branch, not the master branch
  • When resolving a specific issue, it's referenced in the PR's title (i.e. [...] (fixes #xxx[,#xxx]), where "xxx" is the issue number)
  • It should address only one issue or feature. If adding multiple features or fixing a bug and adding a new feature, break them into separate PRs if at all possible.
  • The title should follow the Conventional Commits naming convention (i.e. fix(alert): not alerting during SSR render, docs(badge): update pill examples, chore(docs): fix typo in README, etc.). This is very important, as the CHANGELOG is generated from these messages, and determines the next version type (patch or minor).

If new features/enhancement/fixes are added or changed:

  • Includes documentation updates
  • Includes component package.json meta section updates (prop, slot and event changes/updates)
  • Includes any needed TypeScript declaration file updates
  • New/updated tests are included and passing (required for new features and enhancements)
  • Existing test suites are passing
  • CodeCov for patch has met target (all changes/updates have been tested)
  • The changes have not impacted the functionality of other components or directives
  • ARIA Accessibility has been taken into consideration (Does it affect screen reader users or keyboard only users? Clickable items should be in the tab index, etc.)

If adding a new feature, or changing the functionality of an existing feature, the PR's
description above includes:

  • A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

@vercel
Copy link

vercel bot commented Nov 20, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/bootstrap-vue/bootstrap-vue/6wdqmsgq1LcpMCi6sopatKZJawdR
✅ Preview: https://bootstrap-vue-git-fork-xanf-vue3-compat-build-bootstrap-vue.vercel.app

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 20, 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 24f4da1:

Sandbox Source
BootstrapVue Starter Project Configuration
BootstrapVue Nuxt.js Starter Project Configuration

@xanf
Copy link
Member Author

xanf commented Dec 1, 2021

minor updates:

Now, tests should be green right after checkout :)

@codecov
Copy link

codecov bot commented Dec 15, 2021

Codecov Report

Merging #6845 (5a0ec4c) into dev (9f70574) will decrease coverage by 1.00%.
The diff coverage is 96.88%.

❗ Current head 5a0ec4c differs from pull request most recent head 24f4da1. Consider uploading reports for the commit 24f4da1 to get more accurate results
Impacted file tree graph

@@             Coverage Diff             @@
##               dev    #6845      +/-   ##
===========================================
- Coverage   100.00%   98.99%   -1.01%     
===========================================
  Files          299      305       +6     
  Lines        10265    10431     +166     
  Branches      2527     2573      +46     
===========================================
+ Hits         10265    10326      +61     
- Misses           0       80      +80     
- Partials         0       25      +25     
Flag Coverage Δ
unittests 98.99% <96.88%> (-1.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/components/form-group/form-group.js 100.00% <ø> (ø)
src/components/layout/row.js 100.00% <ø> (ø)
src/directives/scrollspy/scrollspy.js 100.00% <ø> (ø)
src/utils/cache.js 19.04% <14.28%> (-80.96%) ⬇️
src/directives/popover/popover.js 93.47% <66.66%> (-6.53%) ⬇️
src/directives/tooltip/tooltip.js 93.33% <66.66%> (-6.67%) ⬇️
src/utils/get-event-root.js 75.00% <75.00%> (ø)
src/components/transporter/transporter.js 18.03% <83.33%> (-81.97%) ⬇️
src/utils/safe-vue-instance.js 83.33% <83.33%> (ø)
src/components/tooltip/helpers/bv-tooltip.js 97.35% <88.23%> (-2.65%) ⬇️
... and 196 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9f70574...24f4da1. Read the comment docs.

Add basic setup for running tests with vue3 compat
Vue3 compat build fails so hard when you have a Vue component
inside provide. To avoid this replace direct provides with
combination of getter functions and computed
Vue 3 compat does not allow to pass parent as parameter
to new Vue instance, so we need to introduce a mixin
to handle that. In future root mixin might be replaced
with some tiny emitter like mitt
* fixes vModel issues
* fixes rendering problems for functional components
* expose new helpers: isVue3, nextTick
Replace __vue__ with platform dependent access
It seems Vue 2 and Vue 3 are not consistent about when lifecycle
hooks are called. Unify this behavior
There is no way to answer, if we have listeners for even when using
Vue3 compat build with $on available. Disable these tests for now,
these could be enabled later, when INSTANCE_EVENT_EMITTER flag will
be disabled
* @vue/test-utils v2 does not allow stub transitions ATM
Vue 3 and Vue 2 seems to have different order of execution, so in
order to get rid of depending on it - just fetch a fresh $tip
inside setInterval for visibility check
localVue implementation provided by vue-test-utils-compat is
limited and does not allow us to cover all use cases
Getting component instance from directive is different in
Vue 2 and Vue 3. Introduce new util to solve this
* correctly handle `null` inside children
* fix test
* nextTick after mounted ensures entire tree is mounted
* make sure compatConfig is merged for mixins and extends
* make some "global" compatConfigs for bootstrap-vue
* use as low number of compat flags as possible
* patch portal-vue and vue-router components with compatConfig
@xanf
Copy link
Member Author

xanf commented Jan 28, 2022

Superseeded by #6905

@xanf xanf closed this Jan 28, 2022
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.

None yet

1 participant