Skip to content

Fixes #37256 - Remove href from labels to prevent warnings #11398

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pavanshekar
Copy link
Contributor

@pavanshekar pavanshekar commented May 21, 2025

What are the changes introduced in this pull request?

Removed the href attributes from the Label components, so they no longer render as anchors, and relies solely on their onClick handlers to open the modals. This stops any unintended navigation and resolves the React “cannot update during render” warnings.

Considerations taken when implementing this change?

Confirmed that click behavior and modal logic remain fully functional across supported browsers and that no new console errors appear.

What are the testing steps for this pull request?

  1. Navigate to Hosts -> All Hosts -> Click on the host -> Change host content source
  2. Click the 'Hosts to update' label
  3. Ensure that there are no warnings/errors in the console and that the modal opens up

Summary by Sourcery

Bug Fixes:

  • Remove href from Label to prevent unintended navigation and React “cannot update during render” warnings

Copy link

sourcery-ai bot commented May 21, 2025

Reviewer's Guide

Host count labels are converted from anchor elements with href to button elements, eliminating unintended navigation and React warnings while preserving modal click functionality.

Sequence Diagram: Label Click to Modal Display

sequenceDiagram
    actor User
    participant LabelButton as "Label (as button)"
    participant ComponentLogic as "UI Component Logic"
    participant Modal

    User->>LabelButton: Clicks Label
    LabelButton->>ComponentLogic: Executes onClick handler (e.g., setModalState(true))
    ComponentLogic->>Modal: Triggers Modal display
    Modal-->>User: Shows Modal content
Loading

File-Level Changes

Change Details Files
Convert Label components from anchors to buttons to remove href attributes and rely on onClick handlers
  • Replace href="#" with as="button" on green Host label
  • Replace href="#" with as="button" on orange Host ignored label
webpack/scenes/Hosts/ChangeContentSource/components/Hosts.js

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @pavanshekar - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -26,9 +26,9 @@ const Hosts = ({
{ __('Some hosts are not registered as content hosts and will be ignored.') }
</p>
}
{contentHosts.length > 0 && (<Label color="green" href="#" onClick={() => setModalHosts(true)}>{titleHosts}: {contentHosts.length}</Label>)}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Removing href may break keyboard accessibility

To restore keyboard focus, render the Label as a native button (e.g. <Label as="button" …>) or add role="button" and tabIndex={0}.

@pavanshekar
Copy link
Contributor Author

@sourcery-ai review

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @pavanshekar - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Member

@sjha4 sjha4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there other pages in the UI with similar console warnings? I remember seeing this when navigating to some pages on the CV UI.

@pavanshekar
Copy link
Contributor Author

Are there other pages in the UI with similar console warnings? I remember seeing this when navigating to some pages on the CV UI.

A similar warning is also present in the RoutedTabs component on the Content View Details page. This warning occurs because state updates or navigation are being triggered during the render phase of the component, which conflicts with React’s lifecycle. This happens as the navigation logic inside RoutedTabs tries to update the location or active state while React is still rendering, leading to the warning.

Copy link
Member

@chris1984 chris1984 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and works well

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.

3 participants