Fix duplicated data-testid on mvx-button host and inner <button>#302
Fix duplicated data-testid on mvx-button host and inner <button>#302arhtudormorar merged 3 commits intomainfrom
data-testid on mvx-button host and inner <button>#302Conversation
Summary of ChangesHello @arhtudormorar, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a testing incompatibility by refining how the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
…` on `mvx-button`
There was a problem hiding this comment.
Code Review
This pull request correctly fixes an issue with duplicated data-testid attributes that violate Playwright's strict mode. The fix involves adding a componentDidRender lifecycle hook to remove the data-testid from the host element. While this solution is effective, I've provided feedback on a more idiomatic Stencil approach using @Prop({ reflect: false }) which would achieve the same result in a more declarative way, removing the need for the added lifecycle hook.
| componentDidRender() { | ||
| if (this.hostElement.hasAttribute('data-testid')) { | ||
| this.hostElement.removeAttribute('data-testid'); | ||
| } | ||
| } |
There was a problem hiding this comment.
While this approach works, a more declarative and idiomatic way to achieve this in Stencil is to prevent the prop from being reflected to the host element's attributes in the first place. You can do this by setting reflect: false on the @Prop decorator for dataTestId.
This would prevent the attribute from being added to the host element, eliminating the need for this lifecycle hook to remove it manually.
For example:
// If the attribute is `data-test-id` (from `dataTestId` prop)
@Prop({ reflect: false }) dataTestId?: string = '';
// If the attribute is `data-testid`
@Prop({ attribute: 'data-testid', reflect: false }) dataTestId?: string = '';This change would make the component's logic cleaner and avoid manual DOM manipulation.
…es on host and inner button
Title
Fix duplicated
data-testidonmvx-buttonby disabling host reflectionSummary
This PR fixes Playwright strict-mode violations caused by
mvx-buttonrendering two DOM nodes with the samedata-testid:<mvx-button>reflected thedata-testidattribute.<button>also received the samedata-testid.Because of this, selectors like
getByTestId('btnPing')orgetByTestId('btnPong')could resolve to two elements, triggering strict-mode errors.Changes
Kept the existing public API so consumers can continue to pass
data-testidtomvx-button.Updated the
dataTestIdprop to stop reflecting the attribute onto the host element:@prop({ attribute: 'data-testid', reflect: false }) dataTestId?: string = '';