Skip to content

feat(Utility): improve addScript method#8116

Merged
ArgoZhang merged 1 commit into
mainfrom
feat-utility
Jun 14, 2026
Merged

feat(Utility): improve addScript method#8116
ArgoZhang merged 1 commit into
mainfrom
feat-utility

Conversation

@ArgoZhang

@ArgoZhang ArgoZhang commented Jun 14, 2026

Copy link
Copy Markdown
Member

Link issues

fixes #8115

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 dynamic script loading utility to track and handle load success or failure states more robustly.

Bug Fixes:

  • Ensure the script loader correctly detects when a script has finished loading by using consistent string-based state markers.

Enhancements:

  • Add explicit error handling and logging for failed script loads while simplifying the script loading promise resolution behavior.

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

sourcery-ai Bot commented Jun 14, 2026

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

Reviewer's Guide

Refines the dynamic script-loading utility to distinguish between successful and failed loads using attribute-based state and cleans up the polling logic accordingly.

Sequence diagram for updated addScript script-loading flow

sequenceDiagram
    participant Caller
    participant addScript
    participant Document
    participant scriptElement
    participant Timer
    participant Console

    Caller->>addScript: addScript(content)
    addScript->>Document: querySelectorAll
    alt scriptElement exists
        addScript->>scriptElement: setAttribute(src, content)
    else no scriptElement
        addScript->>Document: createElement(script)
        addScript->>scriptElement: setAttribute(src, content)
        addScript->>Document: appendChild(scriptElement)
    end
    addScript->>scriptElement: onload = () => setAttribute(loaded, 'true')
    addScript->>scriptElement: onerror = () => setAttribute(loaded, 'error')
    addScript->>Timer: setInterval(handler, 20)

    loop polling
        Timer->>scriptElement: getAttribute(loaded)
        alt state is 'true'
            addScript->>Timer: clearInterval
            addScript-->>Caller: resolve()
        else state is 'error'
            addScript->>Timer: clearInterval
            addScript->>Console: console.error
            addScript-->>Caller: resolve()
        end
    end
Loading

File-Level Changes

Change Details Files
Improve script loading in addScript by tracking success vs. error state and simplifying the polling promise.
  • Set the script element's 'loaded' attribute to string values 'true' or 'error' instead of a boolean-like value
  • Add an onerror handler to mark failed loads with 'loaded' = 'error'
  • Remove the unused promise rejection path and resolve the promise for both success and error cases
  • Refactor the polling loop to check the 'loaded' state, stop the interval on completion, log an error for failures, and always resolve the promise
src/BootstrapBlazor/wwwroot/modules/utility.js

Assessment against linked issues

Issue Objective Addressed Explanation
#8115 Improve the Utility addLink method implementation (e.g., its loading state handling and robustness).

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 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:

  • Instead of polling the loaded attribute with setInterval, consider resolving the promise directly in the onload/onerror handlers and cleaning up event listeners to avoid unnecessary timers and potential hanging if neither event fires.
  • Right now the promise resolves both on success and error; if callers need to distinguish failures, consider rejecting on error or returning a more explicit result object so error handling can be done upstream.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Instead of polling the `loaded` attribute with `setInterval`, consider resolving the promise directly in the `onload`/`onerror` handlers and cleaning up event listeners to avoid unnecessary timers and potential hanging if neither event fires.
- Right now the promise resolves both on success and error; if callers need to distinguish failures, consider rejecting on error or returning a more explicit result object so error handling can be done upstream.

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.

@ArgoZhang ArgoZhang enabled auto-merge (squash) June 14, 2026 00:37

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 updates the dynamic script-loading helper in utility.js to track load state using string markers and to handle load failures without hanging indefinitely.

Changes:

  • Track script load state via loaded="true" / loaded="error" attributes.
  • Add onerror handling and log a message when script loading fails.
  • Simplify the returned promise to always resolve (no explicit rejection path).

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

Comment thread src/BootstrapBlazor/wwwroot/modules/utility.js
Comment thread src/BootstrapBlazor/wwwroot/modules/utility.js
Comment thread src/BootstrapBlazor/wwwroot/modules/utility.js
@codecov

codecov Bot commented Jun 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (873b60a) to head (75225e6).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #8116   +/-   ##
=========================================
  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.

@ArgoZhang ArgoZhang changed the title feat(Utility): improve addLink method feat(Utility): improve addScript method Jun 14, 2026
@ArgoZhang ArgoZhang merged commit 9ce91e9 into main Jun 14, 2026
8 checks passed
@ArgoZhang ArgoZhang deleted the feat-utility branch June 14, 2026 01:21
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 addScript method

2 participants