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(id) use universally unique ids for the id mixin (fixes #7004) #7021

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

stam
Copy link

@stam stam commented Aug 1, 2022

Describe the PR

Make the id mixin use a universally unique id. Previously vue's internal id was used.
This is a locally unique id, but when there are multiple vue bundles on the same page it's not globally unique anymore. (#7004)

Because these ids are used to link labels to checkboxes or form elements, using local ids lead to some undefined behavior where checkboxes stopped working because they pointed to an id in use by another input element.

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 (please describe)

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

  • No
  • 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 Aug 1, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
bootstrap-vue ✅ Ready (Inspect) Visit Preview Sep 1, 2022 at 0:45AM (UTC)

@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 1, 2022

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 25cd124:

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

@codecov
Copy link

codecov bot commented Aug 1, 2022

Codecov Report

Merging #7021 (daeb3e4) into dev (fab4161) will not change coverage.
The diff coverage is 100.00%.

❗ Current head daeb3e4 differs from pull request most recent head 25cd124. Consider uploading reports for the commit 25cd124 to get more accurate results

@@            Coverage Diff            @@
##               dev     #7021   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          299       299           
  Lines        10265     10270    +5     
  Branches      2527      2528    +1     
=========================================
+ Hits         10265     10270    +5     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

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

Impacted Files Coverage Δ
src/mixins/id.js 100.00% <100.00%> (ø)

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 fab4161...25cd124. Read the comment docs.

@stam
Copy link
Author

stam commented Aug 17, 2022

Does anyone know why the CI pipeline has been stuck for >2 weeks?

@xanf
Copy link
Member

xanf commented Oct 3, 2022

@stam thank you for your contribution! Having UUID seems a bit of overkill for me (that will be leeeeeengthy IDs).

Also this will cause problems for tests which are using snapshots - because each time local id will be updated (yeah, we can solve it by writing smart serializer but I prefer not to break existing user experience unless really needed)

I can suggest two approaches, both are fine for me:

  • Minimal change

Expose new method setIdPrefix. So if you have multiple Vue apps, you can call setIdPrefix in each app and solve it

  • A bit bigger change

Just making a global counter in the module, which autoincrements each time :)
We could expose extra method setLocalIdInitialValue which will explicitly set this counter. This will serve two things:

  • if (for some reason) you will have multiple bootstrap-vue instances on the page you could do something like setLocalIdInitialValue(1000000) for first one and setLocalIdInitialValue(2000000) for second (ugly, but still works :))
  • in tests we could call
beforeEach(() => setLocalIdInitialValue(0));

making all snapshot tests work reliably

WDYT?

@xanf xanf self-assigned this Oct 3, 2022
@VividLemon
Copy link
Member

VividLemon commented Oct 4, 2022

Having UUID seems a bit of overkill for me

This is BV3's implementation:

/**
 * @param suffix
 * @returns
 */
export default (suffix = ''): string =>
  `__BVID__${Math.random().toString().slice(2, 8)}___BV_${suffix}__`

Generally, it's written as a composable to the same affect as the mixin you use. Six "random" numbers and a suffix seems good enough to prevent any possible overlaps.

@xanf
Copy link
Member

xanf commented Oct 4, 2022

@VividLemon this is an approach I would like to avoid - it will generate totally new IDs on each run :)

@VividLemon
Copy link
Member

@VividLemon this is an approach I would like to avoid - it will generate totally new IDs on each run :)

Seems like it would be desirable to avoid conflicts.

@stam
Copy link
Author

stam commented Oct 5, 2022

Hey @xanf
Before we work around the constraint of "not breaking snapshot tests", can we first verify that they are currently working?
The current bootstrap-vue behavior uses the incrementing internal ID of vue.
Which means that snapshot tests only succeed if they are being executed in the right order.

If you have snapshot test 1,2,3,4 & 5 and add test 2a, snapshot tests 3, 4 & 5 will break.
If you run test 2 individually, it will break.

I seriously doubt anyone is snapshot testing bootstrap-vue components without passing an id prop.

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

3 participants