Skip to content

fix(Message): handle queued messages and repeated dismissal - #8773

Merged
ArgoZhang merged 4 commits into
mainfrom
fix-message
Nov 17, 2026
Merged

ArgoZhang merged 4 commits into
mainfrom
fix-message

Conversation

@ArgoZhang

@ArgoZhang ArgoZhang commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Link issues

fixes #8772

Summary By Copilot

  • Track pending Message items so every still-active message requested before a render is initialized.
  • Remove pending items when they are cleared or replaced, and remove dismissed messages even when no OnDismiss callback is configured.
  • Share an idempotent JavaScript close path between manual dismissal and auto-hide so the same item is processed once.
  • Update MessageTest.Placement_Ok to retain the alert ID before dismissal removes its DOM element.

Regression?

  • Yes
  • No

No intentional regression; the changes are limited to Message lifecycle handling.

Risk

  • High
  • Medium
  • Low

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?

  • 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

Keep Message, Toast, and SweetAlert state consistent across concurrent or repeated actions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sourcery-ai

sourcery-ai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Implementation

Coordinate pending Message activation and removal in component state with idempotent JavaScript close handling, so repeated actions do not operate on already-closed messages.

  • src/BootstrapBlazor/Components/Message/Message.razor.cs L79-89, L144-153 (+5 small edits)
  • src/BootstrapBlazor/Components/Message/Message.razor.js L27-41 (+3 small edits)

Tests

Keep the message ID available while dismissing and clearing the message in the unit test.

  • test/UnitTest/Components/MessageTest.cs L98-101

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

@bb-auto bb-auto Bot added this to the v11.1.0 milestone Nov 17, 2026
@bb-auto bb-auto Bot added the bug Something isn't working label Nov 17, 2026

@bb-auto bb-auto Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Auto approved by bb-auto

@sourcery-ai

sourcery-ai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Linked issues

Checked at commit a159c46

#8772 bug(Notifications): prevent duplicate popup actions · 1 of 3 met

# Requirement Status Notes
1 Handle each close or confirm action once across Message, Toast, and SweetAlert. 🟡 Partly met Message removes the item before awaiting its callback and guards repeated JS closes, but Toast still awaits its callback before removing the item, and SweetAlert callbacks have no in-progress guard.
2 Activate all Message items queued in the same render cycle. ✅ Met Message snapshots and clears the pending set after rendering, then activates each item that is still present.
3 Return without waiting on an active popup's result when a SweetAlert request is ignored. ❌ Not addressed ShowModal still awaits the new option's confirmation task even though the active-popup path does not assign that option a confirmation context.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@bb-auto bb-auto Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Auto approved by bb-auto

@codecov

codecov Bot commented Nov 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (4ea83f8) to head (a159c46).

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     
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 Harness.
📢 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.

@ArgoZhang ArgoZhang changed the title fix(Notifications): prevent repeated popup actions fix(Message): handle queued messages and repeated dismissal Nov 17, 2026
@ArgoZhang
ArgoZhang merged commit e4384b2 into main Nov 17, 2026
7 checks passed
@ArgoZhang
ArgoZhang deleted the fix-message branch November 17, 2026 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(Message): handle queued messages and repeated dismissal

1 participant