Skip to content

feat(DynamicElement): implement IDisposeAsync interface#7896

Merged
ArgoZhang merged 2 commits intomainfrom
refactor-dy
Apr 19, 2026
Merged

feat(DynamicElement): implement IDisposeAsync interface#7896
ArgoZhang merged 2 commits intomainfrom
refactor-dy

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented Apr 19, 2026

Link issues

fixes #7895

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

Implement asynchronous disposal support for dynamic UI elements and align related documentation comments.

Enhancements:

  • Make DynamicElement implement IAsyncDisposable with an async disposal pattern that clears event handlers and child content.
  • Update XML documentation comments for the JavaScript isolation base component to use consistent BootstrapBlazor naming and clarified Chinese descriptions.

Copilot AI review requested due to automatic review settings April 19, 2026 06:52
@bb-auto bb-auto bot added the enhancement New feature or request label Apr 19, 2026
@bb-auto bb-auto bot added this to the v10.5.0 milestone Apr 19, 2026
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Apr 19, 2026

Reviewer's Guide

Implements asynchronous disposal for DynamicElement and improves documentation comments in BootstrapModuleComponentBase, ensuring proper cleanup of event handlers and consistent XML doc strings.

Sequence diagram for DynamicElement asynchronous disposal flow

sequenceDiagram
    participant Caller
    participant DynamicElement
    participant GC

    Caller->>DynamicElement: DisposeAsync()
    activate DynamicElement
    DynamicElement->>DynamicElement: DisposeAsync(true)
    activate DynamicElement
    DynamicElement->>DynamicElement: Clear OnClick
    DynamicElement->>DynamicElement: Clear OnDoubleClick
    DynamicElement->>DynamicElement: Clear OnContextMenu
    DynamicElement->>DynamicElement: Clear ChildContent
    deactivate DynamicElement
    DynamicElement->>GC: SuppressFinalize(this)
    deactivate DynamicElement
    GC-->>Caller: Finalization suppressed for DynamicElement
Loading

Class diagram for DynamicElement implementing IAsyncDisposable

classDiagram
    class BootstrapComponentBase

    class IAsyncDisposable {
        <<interface>>
        +DisposeAsync() ValueTask
    }

    class DynamicElement {
        +string TagName
        +RenderFragment ChildContent
        +EventCallback OnClick
        +EventCallback OnDoubleClick
        +EventCallback OnContextMenu
        +Task OnTriggerClick(MouseEventArgs e)
        +Task OnTriggerDoubleClick(MouseEventArgs e)
        +Task OnTriggerContextMenu(MouseEventArgs e)
        +DisposeAsync() ValueTask
        #DisposeAsync(bool disposing) ValueTask
    }

    DynamicElement --|> BootstrapComponentBase
    DynamicElement ..|> IAsyncDisposable
Loading

File-Level Changes

Change Details Files
Implement IAsyncDisposable on DynamicElement and add async disposal logic to clear delegates and content.
  • Change DynamicElement base class declaration to also implement IAsyncDisposable.
  • Add a protected virtual DisposeAsync(bool disposing) method that nulls event callbacks and ChildContent when disposing is true.
  • Add a public DisposeAsync() implementation that calls the protected overload and suppresses finalization.
src/BootstrapBlazor/Components/BaseComponents/DynamicElement.cs
Tighten and align XML documentation on BootstrapModuleComponentBase.
  • Adjust Chinese XML summary text to use the correct product name without spacing in both zh and en comments.
  • Update the zh DisposeAsync(bool) comment to clearly state it performs asynchronous resource cleanup.
src/BootstrapBlazor/Components/BaseComponents/BootstrapModuleComponentBase.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#7895 Make DynamicElement implement an async disposal interface (IDisposeAsync/IAsyncDisposable) and provide an appropriate async dispose method.

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

@ArgoZhang ArgoZhang merged commit f559e9e into main Apr 19, 2026
6 checks passed
@ArgoZhang ArgoZhang deleted the refactor-dy branch April 19, 2026 06:52
Copy link
Copy Markdown
Contributor

@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 - I've left some high level feedback:

  • In DynamicElement, DisposeAsync(bool disposing) never awaits anything, so it doesn’t need to be async—you can remove async and return ValueTask.CompletedTask when appropriate, and have DisposeAsync() directly return the ValueTask instead of awaiting it.
  • Consider aligning the disposal pattern in DynamicElement with the existing async disposal conventions in the codebase (e.g., a DisposeAsyncCore-style method) for consistency with other components implementing IAsyncDisposable.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `DynamicElement`, `DisposeAsync(bool disposing)` never awaits anything, so it doesn’t need to be `async`—you can remove `async` and return `ValueTask.CompletedTask` when appropriate, and have `DisposeAsync()` directly return the `ValueTask` instead of awaiting it.
- Consider aligning the disposal pattern in `DynamicElement` with the existing async disposal conventions in the codebase (e.g., a `DisposeAsyncCore`-style method) for consistency with other components implementing `IAsyncDisposable`.

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
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Implements async disposal support for DynamicElement and aligns XML documentation wording around async resource disposal in the base JS-module component.

Changes:

  • Make DynamicElement implement IAsyncDisposable and add DisposeAsync methods to clear delegate/content references.
  • Update BootstrapModuleComponentBase XML docs to use consistent “BootstrapBlazor” naming and improve the Chinese description for async disposal.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/BootstrapBlazor/Components/BaseComponents/DynamicElement.cs Adds IAsyncDisposable implementation and async-dispose pattern methods.
src/BootstrapBlazor/Components/BaseComponents/BootstrapModuleComponentBase.cs Documentation-only adjustments for naming and async-dispose summary text.

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

Comment on lines +185 to +194
protected virtual async ValueTask DisposeAsync(bool disposing)
{
if (disposing)
{
OnClick = null;
OnDoubleClick = null;
OnContextMenu = null;
ChildContent = null;
}
}
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

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

DisposeAsync(bool disposing) is marked async but contains no await. This will trigger CS1998 and also allocates an unnecessary async state machine on every dispose. Since the method only clears references, make it non-async and return a completed ValueTask (or make it ValueTask returning without async).

Copilot uses AI. Check for mistakes.
Comment on lines +199 to +203
public async ValueTask DisposeAsync()
{
await DisposeAsync(true);
GC.SuppressFinalize(this);
}
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

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

DisposeAsync() is async solely to await DisposeAsync(true). If DisposeAsync(bool) is changed to return a completed ValueTask synchronously, consider making this method non-async too and returning the ValueTask directly (still calling GC.SuppressFinalize(this)), to avoid an extra state machine allocation.

Copilot uses AI. Check for mistakes.
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (c2dcc2e) to head (0ae6ffc).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #7896   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          764       764           
  Lines        34200     34213   +13     
  Branches      4705      4706    +1     
=========================================
+ Hits         34200     34213   +13     
Flag Coverage Δ
BB 100.00% <100.00%> (?)

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

☔ View full report in Codecov by Sentry.
📢 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.

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(DynamicElement): implement IDisposeAsync interface

2 participants