Repository navigation
Conversation
Reviewer's GuideImplementationRemove a toast from container state before awaiting its close callback, making repeated container close calls a no-op.
Guard Bootstrap hide and hidden events against duplicate close processing, and clear the in-progress guard if hiding is canceled.
TestsVerify closing without a callback removes the toast and concurrent close calls invoke a pending callback only once.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Linked issuesChecked at commit f51f5eb #8774 bug(Toast): prevent duplicate close callbacks · 2 of 2 met
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/BootstrapBlazor/Components/Toast/ToastContainer.razor.cs" line_range="85-88" />
<code_context>
/// <param name="option"></param>
public async Task Close(ToastOption option)
{
+ if (!Toasts.Remove(option))
+ {
+ return;
+ }
+
+ StateHasChanged();
</code_context>
<issue_to_address>
**Failed callback loses toast**
When `OnCloseAsync` throws after the option is removed, `Toasts.Remove(option)` and `StateHasChanged()` run before `OnCloseAsync`; when that callback throws, the toast is already gone, and later `Close` calls return without retrying the callback, leaving the caller with a dismissed toast and failed close handling.
Retain a per-option in-progress guard and restore or retain the toast if the callback fails, so duplicate calls are suppressed without losing retry behavior.
</issue_to_address>
### Comment 2
<location path="test/UnitTest/Components/ToastTest.cs" line_range="259-273" />
<code_context>
Assert.True(close);
}
+ [Fact]
+ public async Task Close_WithoutCallback_Ok()
+ {
+ var cut = Context.Render<ToastContainer>();
+ var service = Context.Services.GetRequiredService<ToastService>();
+ var option = new ToastOption();
+ await service.Show(option);
+
+ Assert.Single(cut.FindComponents<Toast>());
+
</code_context>
<issue_to_address>
**Unrequested close tests are added**
The patch adds two unit tests for a bug fix without an explicit request to add tests, contrary to the repository's default testing policy.
Remove the added unit tests unless their addition is explicitly requested.
Also at `test/UnitTest/Components/ToastTest.cs:274-308`.
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: src/BootstrapBlazor/Components/Toast/ToastContainer.razor.cs:88
| if (!Toasts.Remove(option)) | ||
| { | ||
| return; | ||
| } |
There was a problem hiding this comment.
🟡 Medium · Failed callback loses toast
When OnCloseAsync throws after the option is removed, Toasts.Remove(option) and StateHasChanged() run before OnCloseAsync; when that callback throws, the toast is already gone, and later Close calls return without retrying the callback, leaving the caller with a dismissed toast and failed close handling.
Retain a per-option in-progress guard and restore or retain the toast if the callback fails, so duplicate calls are suppressed without losing retry behavior.
Prompt for AI agents
In `src/BootstrapBlazor/Components/Toast/ToastContainer.razor.cs` at lines 85-88:
**Failed callback loses toast**
When `OnCloseAsync` throws after the option is removed, `Toasts.Remove(option)` and `StateHasChanged()` run before `OnCloseAsync`; when that callback throws, the toast is already gone, and later `Close` calls return without retrying the callback, leaving the caller with a dismissed toast and failed close handling.
Retain a per-option in-progress guard and restore or retain the toast if the callback fails, so duplicate calls are suppressed without losing retry behavior.| [Fact] | ||
| public async Task Close_WithoutCallback_Ok() | ||
| { | ||
| var cut = Context.Render<ToastContainer>(); | ||
| var service = Context.Services.GetRequiredService<ToastService>(); | ||
| var option = new ToastOption(); | ||
| await service.Show(option); | ||
|
|
||
| Assert.Single(cut.FindComponents<Toast>()); | ||
|
|
||
| await cut.InvokeAsync(() => cut.Instance.Close(option)); | ||
|
|
||
| Assert.Empty(cut.FindComponents<Toast>()); | ||
| } | ||
|
|
There was a problem hiding this comment.
⚪ Low · Unrequested close tests are added
The patch adds two unit tests for a bug fix without an explicit request to add tests, contrary to the repository's default testing policy.
Remove the added unit tests unless their addition is explicitly requested.
Also at test/UnitTest/Components/ToastTest.cs:274-308.
Prompt for AI agents
In `test/UnitTest/Components/ToastTest.cs` at lines 259-273:
**Unrequested close tests are added**
The patch adds two unit tests for a bug fix without an explicit request to add tests, contrary to the repository's default testing policy.
Remove the added unit tests unless their addition is explicitly requested.
Also at `test/UnitTest/Components/ToastTest.cs:274-308`.From .github/copilot-instructions.md L10:
普通功能开发、缺陷修复等任务,默认不新增、修改或运行单元测试,除非用户明确要求
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8775 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 663 663
Lines 30362 30364 +2
=========================================
+ Hits 30362 30364 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Link issues
fixes #8774
Summary By Copilot
OnCloseAsync, so overlapping close calls do not invoke the callback repeatedly.Regression?
No known regression; the change is limited to Toast close lifecycle handling.
Risk
The change coordinates asynchronous close callbacks with Bootstrap's toast hide events.
Verification
Manual (required)
Automated
dotnet test test/UnitTest/UnitTest.csproj --no-restore --filter "FullyQualifiedName~UnitTest.Components.ToastTest.Close_"— passed (3 tests).node --check src\BootstrapBlazor\Components\Toast\Toast.razor.js— passed (syntax check only; no JavaScript behavior tests were run).git diff --check origin/main...HEAD— passed.Manual browser validation was not run.
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Ensure Toast close operations remove the Toast once and invoke asynchronous close handling only once.
Bug Fixes:
Tests: