Skip to content

feat(Utility): improve addLink method#8118

Merged
ArgoZhang merged 3 commits into
mainfrom
feat-add-link
Jun 15, 2026
Merged

feat(Utility): improve addLink method#8118
ArgoZhang merged 3 commits into
mainfrom
feat-add-link

Conversation

@ArgoZhang

@ArgoZhang ArgoZhang commented Jun 15, 2026

Copy link
Copy Markdown
Member

Link issues

fixes #8117

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Improve the utility helper for dynamically adding stylesheet links to handle load state more robustly.

Bug Fixes:

  • Ensure dynamically added stylesheets mark their load state correctly using string attributes and resolve the loader even on error to avoid hanging callers.

Enhancements:

  • Add explicit error handling and logging when dynamically added stylesheets fail to load, while simplifying the promise resolution logic.

Copilot AI review requested due to automatic review settings June 15, 2026 01:15
@bb-auto bb-auto Bot added the enhancement New feature or request label Jun 15, 2026
@bb-auto bb-auto Bot added this to the v10.7.0 milestone Jun 15, 2026
@sourcery-ai

sourcery-ai Bot commented Jun 15, 2026

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

Reviewer's Guide

Improves the addLink helper to use string values for its loaded state, handle stylesheet load errors explicitly, and simplify the returned Promise by resolving on either success or failure without rejecting.

Sequence diagram for improved addLink stylesheet loading

sequenceDiagram
    participant Caller
    participant addLink
    participant DocumentHead as document_head
    participant CssLink as css_link
    participant Console as console

    Caller->>addLink: addLink(href, rel)
    addLink->>DocumentHead: appendChild(css_link)
    addLink->>CssLink: setAttribute(loaded, 'true') onload
    addLink->>CssLink: setAttribute(loaded, 'error') onerror
    addLink->>addLink: setInterval(handler, 20)
    addLink->>CssLink: getAttribute(loaded)
    alt state === 'true'
        addLink->>addLink: clearInterval(handler)
        addLink-->>Caller: Promise resolved
    else state === 'error'
        addLink->>addLink: clearInterval(handler)
        addLink->>Console: console.error(href)
        addLink-->>Caller: Promise resolved
    end
Loading

File-Level Changes

Change Details Files
Refine addLink loaded state handling and Promise resolution, including explicit error handling for stylesheet loading.
  • Change the loaded attribute value to use the string 'true' to match string comparisons.
  • Add an onerror handler for dynamically created link elements to set the loaded state to 'error' on failure.
  • Update the polling logic to inspect the loaded state string, resolving the Promise on either 'true' (success) or 'error' (failure).
  • Remove the unused reject callback from the Promise constructor and ensure the interval handler is always cleared on resolution.
src/BootstrapBlazor/wwwroot/modules/utility.js

Assessment against linked issues

Issue Objective Addressed Explanation
#8117 Improve the addLink utility method to more robustly handle stylesheet loading state, including success and failure cases.

Possibly linked issues


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

bb-auto[bot]
bb-auto Bot previously approved these changes Jun 15, 2026

@bb-auto bb-auto 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.

Auto approved by bb-auto

@sourcery-ai sourcery-ai Bot 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.

Hey - I've left some high level feedback:

  • Consider rejecting the promise on onerror instead of resolving, so callers can distinguish between success and failure rather than relying on a console message.
  • If addLink is called multiple times for the same href where the link already exists but has no loaded attribute (e.g., added outside this helper), the polling loop will never resolve; you may want to handle pre-existing links more defensively (e.g., resolve immediately or infer loaded state from sheet/readyState).
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider rejecting the promise on `onerror` instead of resolving, so callers can distinguish between success and failure rather than relying on a console message.
- If `addLink` is called multiple times for the same `href` where the link already exists but has no `loaded` attribute (e.g., added outside this helper), the polling loop will never resolve; you may want to handle pre-existing links more defensively (e.g., resolve immediately or infer loaded state from `sheet`/`readyState`).

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.

Copilot AI 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.

Pull request overview

This PR improves the addLink helper in wwwroot/modules/utility.js to better track the load state of dynamically added stylesheets, aligning its behavior more closely with the existing addScript helper and preventing callers from hanging on load errors.

Changes:

  • Set the loaded attribute using explicit string values ('true' / 'error') instead of a boolean.
  • Add onerror handling for dynamically added <link> elements to mark failure state.
  • Simplify the promise to always resolve, and log an error when stylesheet loading fails.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/BootstrapBlazor/wwwroot/modules/utility.js
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
bb-auto[bot]
bb-auto Bot previously approved these changes Jun 15, 2026

@bb-auto bb-auto 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.

Auto approved by bb-auto

@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (9ce91e9) to head (09d757e).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #8118   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          766       766           
  Lines        34204     34204           
  Branches      4695      4695           
=========================================
  Hits         34204     34204           
Flag Coverage Δ
BB 100.00% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bb-auto bb-auto 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.

Auto approved by bb-auto

@ArgoZhang ArgoZhang merged commit 319e898 into main Jun 15, 2026
7 checks passed
@ArgoZhang ArgoZhang deleted the feat-add-link branch June 15, 2026 01:39
@ArgoZhang ArgoZhang restored the feat-add-link branch June 15, 2026 01:42
@ArgoZhang ArgoZhang deleted the feat-add-link branch June 15, 2026 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(Utility): improve addLink method

2 participants