[dev-v5][AutoComplete Fix @bind:after being called twice - #4981
Merged
Vincent Baaij (vnbaaij) merged 1 commit intoJun 30, 2026
Conversation
Vincent Baaij (vnbaaij)
requested a review
from Denis Voituron (dvoituron)
as a code owner
June 30, 2026 18:09
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes #4754 by preventing duplicate listboxchange events from being raised by ListBoxContainer when Blazor re-renders and re-applies the same selected attributes, which in turn caused @bind-...:after callbacks in FluentAutocomplete to execute twice.
Changes:
- Track the last dispatched selection (
lastSelectedOptions) inListBoxContainer.ts. - Initialize
lastSelectedOptionsafter the firstrefresh(true)during component setup. - Suppress
listboxchangedispatch when the current selected-options signature matches the previously dispatched signature.
|
✅ All tests passed successfully Details on your Workflow / Core Tests page. |
Summary - Unit Tests Code CoverageSummary
CoverageMicrosoft.FluentUI.AspNetCore.Components - 98.5%
|
Vincent Baaij (vnbaaij)
enabled auto-merge (squash)
June 30, 2026 18:20
Denis Voituron (dvoituron)
approved these changes
Jun 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #4754
Why it fires twice
There are two separate triggers that both cause the
MutationObserverto dispatch a listboxchange event:User click – the user picks an option → the fluent-option's selected/current-selected attribute changes →
MutationObserverfires → listboxchange →OnDropdownChangeHandlerAsync(call update project meta data in preparation for publishing #1).Blazor re-render –
OnDropdownChangeHandlerAsyncupdatesSelectedItems,InternalSelectedItemsChangedHandlerAsyncupdates_internalSelectedItems, Blazor re-renders theFluentListboxinside the popover, andFluentOptioncomponents write the selected attribute back to the DOM to match the new state →MutationObserverfires again → listboxchange →OnDropdownChangeHandlerAsync(call Resolve all Warnings and Errors prior to publishing #2).The fix
ListBoxContainer.tsnow trackslastSelectedOptions. InraiseSelectedOptionsChangeEvent, if the current selection string equalslastSelectedOptions, the event is skipped. Blazor's re-render sets the DOM attributes back to the same values that are already selected, so the string matches and the duplicate is suppressed. A genuine user change always produces a different string, so real events still fire normally.