Skip to content

fix(col, form-group): implement self overwriting lazy props getter (fixes: #3080) #3125

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

Merged
merged 22 commits into from
Apr 20, 2019

Conversation

tmorehouse
Copy link
Member

@tmorehouse tmorehouse commented Apr 17, 2019

Describe the PR

Vue supports components defined as factory functions, except when the component is lazy loaded (via a lazy import, or require, that return promises), as it assumes the component is either an object or a Vue.extended object (although this requirement is not documented).

This PR changes how the component is defined, switching back to the plain object format instead of a component factory function, and by replacing props with a self-overwriting lazy getter to generate the props on first access, and subsequently cache the results in the component's options:

export default {
  name: 'BCol',
  get props() {
    delete this.props
    return (this.props = generateProps())
  },
  render(h) {
    //...
  }
}

The first access (via Vue.component(...), Vue.extend(...) or $createElement(...)) will generate the prop definitions and cache them.

Fixes #3080

Side Note; the original issue should really be fixed in Vue (allowing a lazy loaded component to return a factory function)

PR checklist

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

  • Bugfix
  • Feature
  • Enhancement
  • ARIA accessibility
  • Documentation update
  • Other (please describe) Code refactor

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

  • No
  • Yes (please describe)

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, fix typos, chore: fix typo in README, etc). This is very important, as the CHANGELOG is generated from these messages.

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

  • Includes documentation updates (including updating the component's package.json for slot and event changes)
  • New/updated tests are included and passing (if required)
  • Existing test suites are passing
  • 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)

@codecov
Copy link

codecov bot commented Apr 17, 2019

Codecov Report

Merging #3125 into dev will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev    #3125      +/-   ##
==========================================
+ Coverage   99.14%   99.14%   +<.01%     
==========================================
  Files         212      212              
  Lines        3864     3874      +10     
  Branches     1154     1154              
==========================================
+ Hits         3831     3841      +10     
  Misses         26       26              
  Partials        7        7
Impacted Files Coverage Δ
src/components/layout/col.js 100% <100%> (ø) ⬆️
src/components/form-group/form-group.js 100% <100%> (ø) ⬆️
src/utils/config.js 100% <100%> (ø) ⬆️

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 f82f566...ad5125a. Read the comment docs.

@tmorehouse tmorehouse changed the title fix: avoid using component factory functions fix: avoid returning Vue.extended components when returning a factory function Apr 17, 2019
@tmorehouse tmorehouse changed the title fix: avoid returning Vue.extended components when returning a factory function fix(col, form-group): switch to self overwriting lazy props getter (fixes: #3080) Apr 19, 2019
@tmorehouse tmorehouse marked this pull request as ready for review April 19, 2019 18:01
@tmorehouse tmorehouse requested review from pi0 and jacobmllr95 April 19, 2019 18:02
@tmorehouse tmorehouse changed the title fix(col, form-group): switch to self overwriting lazy props getter (fixes: #3080) fix(col, form-group): implement self overwriting lazy props getter (fixes: #3080) Apr 19, 2019
@tmorehouse tmorehouse merged commit 92756bd into dev Apr 20, 2019
@tmorehouse tmorehouse deleted the tmorehouse/dynamic-props branch April 20, 2019 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot read property 'props' of undefined when lazy loading <b-col> and <b-form-group> components
2 participants