Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
namespace BootstrapBlazor.Components;

/// <summary>
/// <para lang="zh">Bootstrap Blazor JavaScript 隔离基类</para>
/// <para lang="en">Bootstrap blazor JavaScript isolation base class</para>
/// <para lang="zh">BootstrapBlazor JavaScript 隔离基类</para>
/// <para lang="en">BootstrapBlazor JavaScript isolation base class</para>
/// </summary>
public abstract class BootstrapModuleComponentBase : IdComponentBase, IAsyncDisposable
{
Expand Down Expand Up @@ -198,7 +198,7 @@ protected async Task InvokeVoidAsync(string identifier, CancellationToken cancel
}

/// <summary>
/// <para lang="zh">Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously</para>
/// <para lang="zh">异步释放资源</para>
/// <para lang="en">Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously</para>
/// </summary>
/// <param name="disposing"></param>
Expand Down
27 changes: 26 additions & 1 deletion src/BootstrapBlazor/Components/BaseComponents/DynamicElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace BootstrapBlazor.Components;
/// <para lang="zh">动态元素组件</para>
/// <para lang="en">Dynamic element component</para>
/// </summary>
public class DynamicElement : BootstrapComponentBase
public class DynamicElement : BootstrapComponentBase, IAsyncDisposable
{
/// <summary>
/// <para lang="zh">获得/设置 TagName 属性 默认为 div</para>
Expand Down Expand Up @@ -176,4 +176,29 @@ private async Task OnTriggerContextMenu(MouseEventArgs e)
await OnContextMenu(e);
}
}

/// <summary>
/// <para lang="zh">异步释放资源</para>
/// <para lang="en">Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously</para>
/// </summary>
/// <param name="disposing"></param>
protected virtual async ValueTask DisposeAsync(bool disposing)
{
if (disposing)
{
OnClick = null;
OnDoubleClick = null;
OnContextMenu = null;
ChildContent = null;
}
}
Comment on lines +185 to +194
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.

/// <summary>
/// <inheritdoc/>
/// </summary>
public async ValueTask DisposeAsync()
{
await DisposeAsync(true);
GC.SuppressFinalize(this);
}
Comment on lines +199 to +203
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.
}
Loading