Skip to content

fix: fixed for auro-hyperlink not being rendered when relative and ta…#312

Merged
alexisiba merged 2 commits into
devfrom
alexisiba/auro-hyperlink-not-rendering-when-relative-and-target-blank-are-set
Nov 11, 2025
Merged

fix: fixed for auro-hyperlink not being rendered when relative and ta…#312
alexisiba merged 2 commits into
devfrom
alexisiba/auro-hyperlink-not-rendering-when-relative-and-target-blank-are-set

Conversation

@alexisiba

@alexisiba alexisiba commented Oct 24, 2025

Copy link
Copy Markdown
Contributor

…rget='_blank' are set

Alaska Airlines Pull Request

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Checklist:

  • My update follows the CONTRIBUTING guidelines of this project
  • I have performed a self-review of my own update

By submitting this Pull Request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Pull Requests will be evaluated by their quality of update and whether it is consistent with the goals and values of this project. Any submission is to be considered a conversation between the submitter and the maintainers of this project and may require changes to your submission.

Thank you for your submission!

-- Auro Design System Team

Summary by Sourcery

Fix auro-hyperlink support for relative URLs by normalizing hrefs properly and treating them as internal so target attributes are applied

Bug Fixes:

  • Update href normalization regex to strip optional protocols and unify leading slashes for relative links
  • Consider relative URLs as internal domain in isAlaskaAirDomain and allow target attribute when relative

@alexisiba
alexisiba requested a review from a team as a code owner October 24, 2025 18:43
@alexisiba alexisiba self-assigned this Oct 24, 2025
@sourcery-ai

sourcery-ai Bot commented Oct 24, 2025

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR enhances ComponentBase to correctly normalize and detect relative URLs as internal links, and updates AuroHyperlink to allow rendering the target attribute for those relative links.

Class diagram for updated ComponentBase and AuroHyperlink

classDiagram
    class ComponentBase {
        +isRelativeUrl(href)
        +normalizeUrl(href)
        +isAlaskaAirDomain(url)
        +relative : boolean
    }
    class AuroHyperlink {
        +target : string
        +includesDomain : boolean
        +relative : boolean
    }
    ComponentBase <|-- AuroHyperlink
Loading

Flow diagram for target attribute rendering logic in AuroHyperlink

flowchart TD
    A["User provides href to AuroHyperlink"] --> B["Check if href is relative"]
    B -->|Yes| C["Set relative = true"]
    B -->|No| D["Check if href includes AlaskaAir domain"]
    C --> E["target attribute rendered if target is set"]
    D --> F["target attribute rendered if target is set and includesDomain is true"]
Loading

File-Level Changes

Change Details Files
Improve relative URL normalization and domain detection in ComponentBase
  • Adjust href normalization regex to strip protocols and normalize leading slashes for relative paths
  • Treat relative URLs as internal AlaskaAir domain in isAlaskaAirDomain logic
src/component-base.mjs
Allow AuroHyperlink to render target attribute for relative links
  • Include relative URL flag in target attribute condition alongside domain check
src/auro-hyperlink.js

Assessment against linked issues

Issue Objective Addressed Explanation
#311 Ensure that auro-hyperlink elements with both target="_blank" and the relative attribute render correctly.

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

@alexisiba alexisiba linked an issue Oct 24, 2025 that may be closed by this pull request
7 tasks

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • Consider adding a guard in isRelativeUrl to handle non-string or empty inputs so you don’t run into runtime errors when url is undefined or null.
  • You might extract isRelativeUrl and the domain check into a shared URL utility module for better reuse across components and easier standalone testing.
  • The regex in isRelativeUrl currently only blocks http(s) and protocol-relative URLs; consider extending it to explicitly exclude other schemes (e.g., mailto:, javascript:) if those should not be treated as relative.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider adding a guard in isRelativeUrl to handle non-string or empty inputs so you don’t run into runtime errors when url is undefined or null.
- You might extract isRelativeUrl and the domain check into a shared URL utility module for better reuse across components and easier standalone testing.
- The regex in isRelativeUrl currently only blocks http(s) and protocol-relative URLs; consider extending it to explicitly exclude other schemes (e.g., mailto:, javascript:) if those should not be treated as relative.

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.

@jordanjones243 jordanjones243 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Something here is still broken. To reproduce this issue, I used this code:

<auro-hyperlink target="_blank" href="/assets/icons/plane.svg" relative>No href supplied</auro-hyperlink><br>
Welcome to <auro-hyperlink target="_blank" href="/assets/icons/plane.svg" relative>Alaska Airlines</auro-hyperlink>.

When testing, I noticed that the first link rendered just fine, but the second link with text surrounding the component is still broke. Let me know if you do not see the same thing and need to discuss this further.

@alexisiba
alexisiba marked this pull request as draft October 31, 2025 21:19
@alexisiba
alexisiba dismissed jordanjones243’s stale review November 4, 2025 23:51

The changes requested are done

@alexisiba
alexisiba force-pushed the alexisiba/auro-hyperlink-not-rendering-when-relative-and-target-blank-are-set branch from 315e20e to 1030bc3 Compare November 5, 2025 00:17
@alexisiba
alexisiba changed the base branch from main to dev November 5, 2025 00:25
@alexisiba
alexisiba marked this pull request as ready for review November 5, 2025 00:26

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `src/component-base.mjs:258-262` </location>
<code_context>
           return url.href;
         }
-        return href.replace(/^[^:]+:/, "");
+        /**
+         * This regex checks if the provided href starts with http:, http:, ftp:, etc...
+         * Also checks if it has // if that matches it replaces it for just one /
+         */
+        return href.replace(/^(?:[^:]+:)?\/\/?/, "/");
     }
   }
</code_context>

<issue_to_address>
**issue (bug_risk):** The updated regex may unintentionally convert protocol-relative URLs to root-relative paths.

This change may break links intended to preserve the host. Please confirm if this behavior is intentional and appropriate for all use cases.
</issue_to_address>

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.

@github-actions

github-actions Bot commented Nov 10, 2025

Copy link
Copy Markdown

🚀 PR Release Published! v0.0.0-pr312.1

To install:

npm install @aurodesignsystem-dev/auro-hyperlink@0.0.0-pr312.1

Install via alias:

npm install @aurodesignsystem/auro-hyperlink@npm:@aurodesignsystem-dev/auro-hyperlink@0.0.0-pr312.1

View on npmjs.com

@jordanjones243
jordanjones243 force-pushed the alexisiba/auro-hyperlink-not-rendering-when-relative-and-target-blank-are-set branch from 1030bc3 to e8310d2 Compare November 10, 2025 18:07
@alexisiba
alexisiba merged commit 7a2e12d into dev Nov 11, 2025
15 of 16 checks passed
@alexisiba
alexisiba deleted the alexisiba/auro-hyperlink-not-rendering-when-relative-and-target-blank-are-set branch November 11, 2025 16:56
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 7.0.0-rc-320.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 8.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions github-actions Bot added the released Completed work has been released label Nov 19, 2025
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 7.0.0-rc-329.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 7.0.0-rc-336.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 7.0.0-rc-339.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

If target="_blank" and relative are used together the auro-hyperlink is crashing

3 participants