Repository navigation
fix(Toast): make close handling idempotent #8775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -256,6 +256,57 @@ public async Task OnCloseAsync_Ok() | |
| 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>()); | ||
|
|
||
| await cut.InvokeAsync(() => cut.Instance.Close(option)); | ||
|
|
||
| Assert.Empty(cut.FindComponents<Toast>()); | ||
| } | ||
|
|
||
|
Comment on lines
+259
to
+273
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⚪ 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 Prompt for AI agentsIn `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 普通功能开发、缺陷修复等任务,默认不新增、修改或运行单元测试,除非用户明确要求 |
||
| [Fact] | ||
| public async Task Close_IgnoresConcurrentCall() | ||
| { | ||
| var closeStarted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); | ||
| var continueClose = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); | ||
| var closeCount = 0; | ||
| var cut = Context.Render<ToastContainer>(); | ||
| var service = Context.Services.GetRequiredService<ToastService>(); | ||
| var option = new ToastOption() | ||
| { | ||
| OnCloseAsync = async () => | ||
| { | ||
| closeCount++; | ||
| closeStarted.TrySetResult(); | ||
| await continueClose.Task; | ||
| } | ||
| }; | ||
| await service.Show(option); | ||
|
|
||
| var firstClose = cut.InvokeAsync(() => cut.Instance.Close(option)); | ||
| Task secondClose = Task.CompletedTask; | ||
| try | ||
| { | ||
| await closeStarted.Task.WaitAsync(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken); | ||
| secondClose = cut.InvokeAsync(() => cut.Instance.Close(option)); | ||
| Assert.Equal(1, closeCount); | ||
| Assert.Empty(cut.FindComponents<Toast>()); | ||
| } | ||
| finally | ||
| { | ||
| continueClose.TrySetResult(); | ||
| } | ||
|
|
||
| await Task.WhenAll(firstClose, secondClose); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void StyleString_Ok() | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium · Failed callback loses toast
When
OnCloseAsyncthrows after the option is removed,Toasts.Remove(option)andStateHasChanged()run beforeOnCloseAsync; when that callback throws, the toast is already gone, and laterClosecalls 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