Skip to content

Alexisiba/relative and default url refactor#316

Merged
rmenner merged 2 commits into
devfrom
alexisiba/relative-and-default-url-refactor
Nov 19, 2025
Merged

Alexisiba/relative and default url refactor#316
rmenner merged 2 commits into
devfrom
alexisiba/relative-and-default-url-refactor

Conversation

@alexisiba

@alexisiba alexisiba commented Nov 18, 2025

Copy link
Copy Markdown
Contributor

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

Refactor URL resolution to always use the current origin, remove legacy relative URL support, and streamline link target and icon logic while updating related tests and build configs

Enhancements:

  • Remove relative URL option and simplify safeUrl to always resolve hrefs against window.location with https protocol
  • Simplify targetIcon logic to only handle same-host vs external links
  • Update hyperlink component to set target attribute for same-domain and relative URLs

Build:

  • Change Node engine requirement to �3E=20 and add .nvmrc
  • Bump @aurodesignsystem/auro-config version to ^1.3.1 and enable publishConfig provenance

Tests:

  • Update hyperlink tests to expect absolute URLs based on window.location and add a test for absolute hrefs
  • Remove obsolete safeUrl relative URL test

@alexisiba
alexisiba requested a review from a team as a code owner November 18, 2025 19:53
@sourcery-ai

sourcery-ai Bot commented Nov 18, 2025

Copy link
Copy Markdown

Reviewer's Guide

This PR refactors URL handling in ComponentBase to remove the relative flag and unify safeUrl logic using window.location as base, updates domain checks for target icons, adjusts AuroHyperlink target attribute behavior, aligns tests with the new URL resolution, and refreshes package and environment configurations.

Sequence diagram for safeUrl resolution with window.location

sequenceDiagram
    participant ComponentBase
    participant "window.location"
    ComponentBase->>"window.location": Use window.location.href as base for new URL(href)
    "window.location"-->>ComponentBase: Returns resolved URL
    ComponentBase->>ComponentBase: Set protocol to https
    ComponentBase-->>ComponentBase: Return url.href
Loading

Sequence diagram for targetIcon domain check logic

sequenceDiagram
    participant ComponentBase
    participant "window.location"
    participant "newWindow.svg"
    participant "externalLink.svg"
    ComponentBase->>"window.location": Compare safeUri hostname to window.location.hostname
    alt Hostnames match
        ComponentBase->>"newWindow.svg": generateIconHtml(newWindow.svg)
    else Hostnames differ
        ComponentBase->>"externalLink.svg": generateIconHtml(externalLink.svg)
    end
Loading

Class diagram for updated ComponentBase URL handling

classDiagram
    class ComponentBase {
        - appearance: string
        - download: boolean
        - ondark: boolean
        - variant: string
        - href: string
        + get safeUri()
        + safeUrl(href)
        + targetIcon(target)
    }
    ComponentBase <|-- AuroHyperlink
Loading

Class diagram for updated AuroHyperlink target attribute logic

classDiagram
    class AuroHyperlink {
        + target: string
        + includesDomain: boolean
        + relative: boolean
        + render()
    }
    AuroHyperlink --|> ComponentBase
Loading

File-Level Changes

Change Details Files
Refactored ComponentBase URL handling and domain-based icon logic
  • Removed the relative property and its use in safeUri/safeUrl
  • safeUrl now uses window.location.href as base and always returns an absolute https URL
  • Replaced Alaska-specific domain check with a helper that compares against window.location.hostname
  • Consolidated targetIcon flow to a single branch for new-window vs external icons
src/component-base.mjs
Adjusted AuroHyperlink target attribute logic
  • Updated target attribute binding to apply when includesDomain or relative is true
src/auro-hyperlink.js
Tests updated to match new URL resolution behavior
  • Removed legacy relative flag tests and stale safeUrl assertions
  • Changed relative URL test to expect a fully qualified URL
  • Added a new test case for absolute href behavior
test/auro-hyperlink.test.js
Updated package and environment configuration
  • Loosened Node engine requirement to >=20
  • Bumped @auro-config dependency version
  • Enabled provenance in publishConfig
  • Added .nvmrc for local Node version management
package.json
.nvmrc

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 changed the base branch from main to dev November 18, 2025 19:53

@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:239-238` </location>
<code_context>
       return undefined;
     }

-    const url = new URL(href, "https://www.alaskaair.com");
+    const url = new URL(href, window?.location?.href);

     switch (url.protocol) {
</code_context>

<issue_to_address>
**issue (bug_risk):** Switching URL base to window.location.href may cause issues in non-browser environments.

This approach can cause runtime errors in SSR or non-browser environments where window is undefined. Please add a guard or fallback to handle these cases.
</issue_to_address>

### Comment 2
<location> `test/auro-hyperlink.test.js:37-44` </location>
<code_context>
     );
   });

+  it("auro-hyperlink href is absolute URL", async () => {
+    const el = await fixture(html`
+      <auro-hyperlink href="https://alaskaair.com/auro">It's Auro!</auro-hyperlink>
+    `);
+
+    const anchor = el.shadowRoot.querySelector("a");
+
+    expect(anchor).to.have.attribute("href", "https://alaskaair.com/auro");
+  });
+
</code_context>

<issue_to_address>
**suggestion (testing):** Add tests for invalid or malformed absolute URLs.

Consider adding tests for cases like missing or unsupported protocols to ensure robust handling of malformed URLs.

Suggested implementation:

```javascript
  it("auro-hyperlink href is absolute URL", async () => {
    const el = await fixture(html`
      <auro-hyperlink href="https://alaskaair.com/auro">It's Auro!</auro-hyperlink>
    `);

    const anchor = el.shadowRoot.querySelector("a");

    expect(anchor).to.have.attribute("href", "https://alaskaair.com/auro");
  });

  it("auro-hyperlink handles malformed absolute URL (missing protocol)", async () => {
    const el = await fixture(html`
      <auro-hyperlink href="alaskaair.com/auro">It's Auro!</auro-hyperlink>
    `);

    const anchor = el.shadowRoot.querySelector("a");

    // Expect the href to be rendered as-is, or not at all, depending on component behavior
    expect(anchor).to.have.attribute("href", "alaskaair.com/auro");
  });

  it("auro-hyperlink handles unsupported protocol in absolute URL", async () => {
    const el = await fixture(html`
      <auro-hyperlink href="ftp://alaskaair.com/auro">It's Auro!</auro-hyperlink>
    `);

    const anchor = el.shadowRoot.querySelector("a");

    // Expect the href to be rendered as-is, or not at all, depending on component behavior
    expect(anchor).to.have.attribute("href", "ftp://alaskaair.com/auro");
  });

```

If your component is supposed to validate or sanitize URLs, you may need to update its implementation to handle these cases accordingly. Adjust the assertions if the component is expected to block or modify malformed/unsupported URLs.
</issue_to_address>

### Comment 3
<location> `test/auro-hyperlink.test.js:165` </location>
<code_context>
+describe("safeUrl function", () => {
</code_context>

<issue_to_address>
**suggestion (testing):** Update safeUrl tests to reflect new default base URL behavior.

Please ensure tests cover resolution of relative URLs using window.location.href as the base, rather than the previous hardcoded value.
</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.

Comment thread src/component-base.mjs
@alexisiba alexisiba self-assigned this Nov 19, 2025
@alexisiba alexisiba linked an issue Nov 19, 2025 that may be closed by this pull request
7 tasks
@alexisiba
alexisiba force-pushed the alexisiba/relative-and-default-url-refactor branch from 343be70 to 8095785 Compare November 19, 2025 00:11
@github-actions

github-actions Bot commented Nov 19, 2025

Copy link
Copy Markdown

🚀 PR Release Published! v0.0.0-pr316.2

To install:

npm install @aurodesignsystem-dev/auro-hyperlink@0.0.0-pr316.2

Install via alias:

npm install @aurodesignsystem/auro-hyperlink@npm:@aurodesignsystem-dev/auro-hyperlink@0.0.0-pr316.2

View on npmjs.com

@rmenner
rmenner force-pushed the alexisiba/relative-and-default-url-refactor branch from a6c171c to 1cd7258 Compare November 19, 2025 05:18
@rmenner
rmenner merged commit 5a0e0ec into dev Nov 19, 2025
16 checks passed
@rmenner
rmenner deleted the alexisiba/relative-and-default-url-refactor branch November 19, 2025 05:25
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.

If an auro-hyperlink uses both target="_blank" and relative it doesn't render

2 participants