-
-
Notifications
You must be signed in to change notification settings - Fork 666
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
Require key for conditionally rendered repeated components #2280
Require key for conditionally rendered repeated components #2280
Conversation
Hi, this PR is now ready for review. As the person who previously attempted to address this issue very well said, "Better late than never" 😀 |
lib/rules/require-key-for-conditionally-rendered-repeated-components.js
Outdated
Show resolved
Hide resolved
lib/rules/require-key-for-conditionally-rendered-repeated-components.js
Outdated
Show resolved
Hide resolved
…ndered-repeated-components' into require-key-for-conditionally-rendered-repeated-components
tests/lib/rules/require-key-for-conditionally-rendered-repeated-components.js
Outdated
Show resolved
Hide resolved
…ird asterisk to an underscore is a weird formatting rule
Hi Flo, I noticed that your request for changes was still active, but I think we addressed everything, so that's why I pinged you for a re-review; I'm not sure what the next step should be... is there something that I need to do to address the CI errors? Thanks again for your support |
Esteemed reviewers, this PR has been sitting here for months and Flo has already reviewed it, so I have a few questions that I hope will help push this through:
Thanks |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM now, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late review.
tests/lib/rules/require-key-for-conditionally-rendered-repeated-components.js
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you!
This PR resolves #255
When Vue updates the DOM, it employs a diffing algorithm to enhance efficiency. If elements of the same type are added or removed, Vue attempts to optimize the process by recycling the previous element for the new one. This recycling strategy is an integral part of Vue's optimization efforts to minimize rendering overhead.
However, this clever recycling strategy can sometimes lead to unexpected issues, primarily because it may not properly update the components. By assigning unique keys to each repeated component within the scope of the component, Vue can quickly identify which items have changed, been added, or been removed.
This lint rule is designed to guard against such recycling issues by requiring a unique key attribute on repeated components that are part of a conditional family (v-if, v-else-if, v-else) within the same scope level. The rule not only checks for the presence of a key attribute but also ensures that repeated components within these conditional families have unique keys.
If a component is found to violate this rule, the lint tool will suggest a fix by proposing a unique key based on the component's name and count (e.g., "some-component-2").
By recognizing the unique key attribute, Vue will abandon its recycling strategy and perform a full removal and addition of the new element, thereby ensuring that the component is rendered correctly.