Repository navigation
fix(Message): handle queued messages and repeated dismissal - #8773
Conversation
Keep Message, Toast, and SweetAlert state consistent across concurrent or repeated actions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Reviewer's GuideImplementationCoordinate pending Message activation and removal in component state with idempotent JavaScript close handling, so repeated actions do not operate on already-closed messages.
TestsKeep the message ID available while dismissing and clearing the message in the unit test.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
This reverts commit 7dde6b7.
Linked issuesChecked at commit a159c46 #8772 bug(Notifications): prevent duplicate popup actions · 1 of 3 met
|
There was a problem hiding this comment.
Hey - I've found 5 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/BootstrapBlazor/Components/Toast/Toast.razor.js" line_range="36" />
<code_context>
+ e.preventDefault();
+ }
+ else {
+ toast.closing = true;
+ }
+ })
</code_context>
<issue_to_address>
**Canceled toasts cannot close**
When another `hide.bs.toast` listener cancels the first hide event, the `hide.bs.toast` handler sets `toast.closing` before event dispatch finishes. Because the canceled event does not produce `hidden.bs.toast`, later hides are prevented, leaving the toast visible and its close callback uncalled.
Reset `toast.closing` when the hide event is canceled so a later hide can proceed.
Also at `src/BootstrapBlazor/Components/Toast/Toast.razor.js:35`.
</issue_to_address>
### Comment 2
<location path="src/BootstrapBlazor/Components/Message/Message.razor.cs" line_range="80" />
<code_context>
protected override async Task OnAfterRenderAsync(bool firstRender)
{
+ var messages = _pendingMessages.ToArray();
+ _pendingMessages.Clear();
+
await base.OnAfterRenderAsync(firstRender);
</code_context>
<issue_to_address>
**Queued messages are lost**
When base initialization or a `show` JS interop call fails while messages are queued, `OnAfterRenderAsync` clears `_pendingMessages` before base initialization and `show` calls; if either fails, queued messages are lost, leaving some unshown or rendered without their JavaScript close or auto-hide behavior.
Keep each message pending until its initialization and `show` call succeed, removing it only after activation.
</issue_to_address>
### Comment 3
<location path="src/BootstrapBlazor/Extensions/SwalExtensions.cs" line_range="37" />
<code_context>
+ if (_messages.Contains(option))
+ {
+ await InvokeVoidAsync("show", Id, GetItemId(option));
+ }
}
}
</code_context>
<issue_to_address>
**Accepted confirmation does not complete**
When the same `SwalOption`, with `IsConfirm` initially false, is passed to a second `ShowModal` call while its first dialog is active, the second call resets `option.IsConfirm` to false, but the accepted dialog's `Parse` callbacks read that shared value. Confirm then fails to set `ConfirmContext.Value`, so the accepted `ShowModal` returns false and its confirmation task does not complete.
Keep the confirm state specific to each request instead of letting an ignored request reset the value read by the active dialog's callbacks.
Also at `src/BootstrapBlazor/Extensions/SwalExtensions.cs:35`.
</issue_to_address>
### Comment 4
<location path="src/BootstrapBlazor/Components/SweetAlert/SweetAlertBody.razor.cs" line_range="199-201" />
<code_context>
+ {
+ if (callback != null)
+ {
+ await callback();
+ }
+ _actionCompleted = true;
+ }
+
</code_context>
<issue_to_address>
**Failed actions run again**
When an action callback performs a side effect and then throws, `CloseAsync` resets `_isClosing` in `finally` but sets `_actionCompleted` only after the callback returns. If a callback performs its side effect and then throws, another click invokes it again and repeats that side effect.
Track that an action has started before invoking its callback, and define how a failed action can be retried without repeating completed side effects.
</issue_to_address>
### Comment 5
<location path="src/BootstrapBlazor/Extensions/SwalExtensions.cs" line_range="27-28" />
<code_context>
option.IsConfirm = true;
- await service.Show(option, swal);
- return await option.ConfirmContext.ConfirmTask.Task;
+ var previousContext = option.ConfirmContext;
+ // An accepted request assigns its context before awaiting rendering.
+ var showTask = service.Show(option, swal);
+ var context = option.ConfirmContext;
</code_context>
<issue_to_address>
**Concurrent confirmations cross-talk**
When the same `SwalOption` is submitted concurrently to two distinct `SweetAlert` instances, `ShowModal` captures the option's mutable `ConfirmContext`, while the callbacks created by `Parse` also read that same property when invoked. If the same option is accepted by two `SweetAlert` instances concurrently, the later request replaces the context; confirming the first popup writes to the second request's context, and the first caller receives the wrong result.
Capture and use a request-local confirmation context in the callbacks, rather than dereferencing the mutable context on the shared option.
</issue_to_address>Sourcery assessment
Approval pending. 5 findings to address first.
Blocking findings: src/BootstrapBlazor/Components/Toast/Toast.razor.js:36, src/BootstrapBlazor/Components/Message/Message.razor.cs:80, src/BootstrapBlazor/Extensions/SwalExtensions.cs:37, src/BootstrapBlazor/Components/SweetAlert/SweetAlertBody.razor.cs:201, src/BootstrapBlazor/Extensions/SwalExtensions.cs:28
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8773 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 663 663
Lines 30350 30362 +12
=========================================
+ Hits 30350 30362 +12
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 #8772
Summary By Copilot
OnDismisscallback is configured.MessageTest.Placement_Okto retain the alert ID before dismissal removes its DOM element.Regression?
No intentional regression; the changes are limited to Message lifecycle handling.
Risk
The change coordinates the Message component's pending state, dismissal callback, and JavaScript close lifecycle.
Verification
Manual (required)
Automated
dotnet test test/UnitTest/UnitTest.csproj --no-restore --no-build --filter "FullyQualifiedName~UnitTest.Components.MessageTest.Placement_Ok"— passed (1 test).git diff --check main...HEAD— passed.No browser/manual validation or tests targeting the component JavaScript logic were run.
Packaging changes reviewed?
☑️ Self Check before Merge