Skip to content

feat(ValidateForm): add UnregisterAsyncSubmitButton method#7889

Merged
ArgoZhang merged 2 commits intomainfrom
feat-validate
Apr 18, 2026
Merged

feat(ValidateForm): add UnregisterAsyncSubmitButton method#7889
ArgoZhang merged 2 commits intomainfrom
feat-validate

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented Apr 18, 2026

Link issues

fixes #7888

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

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

Summary by Sourcery

Add support for unregistering async submit buttons from ValidateForm and align button click handling with typed mouse event callbacks.

New Features:

  • Introduce an UnregisterAsyncSubmitButton API on ValidateForm to allow removal of async submit buttons.

Enhancements:

  • Change ButtonBase OnClick to use EventCallback and update its disposal to clear the typed callback.

Copilot AI review requested due to automatic review settings April 18, 2026 08:22
@bb-auto bb-auto bot added the enhancement New feature or request label Apr 18, 2026
@bb-auto bb-auto bot added this to the v10.5.0 milestone Apr 18, 2026
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Apr 18, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds support for unregistering async submit buttons from ValidateForm and updates ButtonBase to use typed MouseEventArgs EventCallback for OnClick, including proper cleanup on disposal.

Sequence diagram for async submit button registration lifecycle

sequenceDiagram
    participant ButtonBase
    participant ValidateForm

    Note over ButtonBase,ValidateForm: ButtonBase is rendered with IsAsync = true inside a ValidateForm

    ButtonBase->>ValidateForm: RegisterAsyncSubmitButton(button)
    ValidateForm->>ValidateForm: AsyncSubmitButtons.Add(button)

    Note over ButtonBase,ValidateForm: Later, when ButtonBase is disposed (e.g., removed from UI)

    ButtonBase->>ValidateForm: UnregisterAsyncSubmitButton(button)
    ValidateForm->>ValidateForm: AsyncSubmitButtons.Remove(button)

    Note over ButtonBase: During disposal
    ButtonBase->>ButtonBase: if OnClick.HasDelegate
    ButtonBase->>ButtonBase: OnClick = EventCallback<MouseEventArgs>.Empty
Loading

Updated class diagram for ValidateForm and ButtonBase

classDiagram
    class ValidateForm {
        - TaskCompletionSource~bool~ _tcs
        + void RegisterAsyncSubmitButton(ButtonBase button)
        + void UnregisterAsyncSubmitButton(ButtonBase button)
        - Task OnValidSubmitForm(EditContext context)
    }

    class ButtonBase {
        <<abstract>>
        + EventCallback<MouseEventArgs> OnClick
        + bool IsAsync
        + ValueTask DisposeAsync(bool disposing)
    }

    class EditContext
    class MouseEventArgs

    ValidateForm --> ButtonBase : manages AsyncSubmitButtons
    ButtonBase ..> ValidateForm : uses
    ButtonBase ..> MouseEventArgs : OnClick payload
    ValidateForm ..> EditContext : used in OnValidSubmitForm()
Loading

File-Level Changes

Change Details Files
Add an API to unregister async submit buttons from ValidateForm.
  • Introduce UnregisterAsyncSubmitButton internal method that removes a button from AsyncSubmitButtons.
  • Document the method in both Chinese and English XML doc comments.
src/BootstrapBlazor/Components/ValidateForm/ValidateForm.razor.cs
Make ButtonBase.OnClick strongly typed with MouseEventArgs and adjust disposal logic.
  • Add using for Microsoft.AspNetCore.Components.Web to access MouseEventArgs.
  • Change OnClick from EventCallback to EventCallback.
  • Update disposal logic to clear OnClick with EventCallback.Empty when it has a delegate.
src/BootstrapBlazor/Components/Button/ButtonBase.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#7888 Add an UnregisterAsyncSubmitButton method to ValidateForm to support unregistering async submit buttons.

Possibly linked issues


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

@ArgoZhang ArgoZhang merged commit 77bb3ef into main Apr 18, 2026
6 checks passed
@ArgoZhang ArgoZhang deleted the feat-validate branch April 18, 2026 08:23
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (39735ce) to head (871e2ee).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #7889   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          764       764           
  Lines        34162     34173   +11     
  Branches      4700      4702    +2     
=========================================
+ Hits         34162     34173   +11     
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 Sentry.
📢 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds support for unregistering async submit buttons from ValidateForm to avoid retaining disposed buttons, and updates button click callback typing.

Changes:

  • Add ValidateForm.UnregisterAsyncSubmitButton and remove disposed async buttons from the form’s tracking list.
  • Unregister async submit buttons during ButtonBase.DisposeAsync to prevent stale references.
  • Change ButtonBase.OnClick from EventCallback to EventCallback<MouseEventArgs>.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/BootstrapBlazor/Components/ValidateForm/ValidateForm.razor.cs Introduces UnregisterAsyncSubmitButton to remove tracked async submit buttons.
src/BootstrapBlazor/Components/Button/ButtonBase.cs Unregisters async buttons on dispose; changes OnClick callback type and adjusts disposal cleanup.
Comments suppressed due to low confidence (1)

src/BootstrapBlazor/Components/Button/ButtonBase.cs:345

  • New behavior relies on unregistering async submit buttons during ButtonBase disposal, but there are existing unit tests around ValidateForm async submit behavior and none appear to cover unregister/dispose interactions. Please add a test that removes/disposes an async submit button and verifies ValidateForm no longer tries to TriggerAsync on it during submit (and does not keep it disabled).
            if (IsAsync && ValidateForm != null)
            {
                ValidateForm.UnregisterAsyncSubmitButton(this);
            }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

/// </summary>
[Parameter]
public EventCallback OnClick { get; set; }
public EventCallback<MouseEventArgs> OnClick { get; set; }
Copy link

Copilot AI Apr 18, 2026

Choose a reason for hiding this comment

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

Changing ButtonBase.OnClick from untyped EventCallback to EventCallback is a public API breaking change and appears unrelated to the ValidateForm unregister feature. This will break consumers that set OnClick from C# (or via reflection/parameter dictionaries) expecting EventCallback. Consider keeping the existing EventCallback OnClick for compatibility (or adding a new typed callback alongside it / marking the old one obsolete) and update release notes accordingly if the breaking change is intended.

Suggested change
public EventCallback<MouseEventArgs> OnClick { get; set; }
public EventCallback OnClick { get; set; }

Copilot uses AI. Check for mistakes.
Comment on lines +585 to +588
internal void UnregisterAsyncSubmitButton(ButtonBase button)
{
AsyncSubmitButtons.Remove(button);
}
Copy link

Copilot AI Apr 18, 2026

Choose a reason for hiding this comment

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

UnregisterAsyncSubmitButton mutates AsyncSubmitButtons while OnValidSubmitForm/OnInvalidSubmitForm iterate that same list across multiple awaits. If an async submit button is disposed/removed while a submit callback is awaiting, this can trigger 'Collection was modified' exceptions during the subsequent foreach loops. To make this robust, consider iterating over a snapshot (e.g., ToArray()) or otherwise guarding list access during submit processing.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(ValidateForm): add UnregisterAsyncSubmitButton method

2 participants