MudMenu: Fix mutation-unsafe async enumeration during close#12757
Merged
danielchalmers merged 7 commits intoMudBlazor:devfrom Feb 28, 2026
Merged
MudMenu: Fix mutation-unsafe async enumeration during close#12757danielchalmers merged 7 commits intoMudBlazor:devfrom
danielchalmers merged 7 commits intoMudBlazor:devfrom
Conversation
…c guard test for the mutation race.
### What I changed
- Fixed mutation-unsafe async enumeration in `MudMenu`:
- [MudMenu.razor.cs](/mnt/f/source/repos/MudBlazor/src/MudBlazor/Components/Menu/MudMenu.razor.cs)
- `CloseMenuAsync()` now snapshots open children before `await`:
- `_subMenus.Where(...).ToArray()`
- `OpenSubMenuAsync()` now snapshots open siblings before `await`:
- `ParentMenu._subMenus.Where(...).ToArray()`
This prevents `InvalidOperation_EnumFailedVersion` when child menus unregister/dispose while close recursion is running.
- Added a deterministic regression unit test (not navigation-timing dependent):
- [MenuTests.cs](/mnt/f/source/repos/MudBlazor/src/MudBlazor.UnitTests/Components/MenuTests.cs)
- New test: `CloseMenu_UnregisteringChildDuringClose_DoesNotThrow`
- It forces child unregister during `CloseMenuAsync()` and asserts no throw.
- Includes a local `BlockingKeyInterceptorService` test double to create the race window deterministically.
- Kept the viewer repro and clarified docs wording:
- [MenuNestedNavigationHrefTest.razor](/mnt/f/source/repos/MudBlazor/src/MudBlazor.UnitTests.Viewer/TestComponents/Menu/MenuNestedNavigationHrefTest.razor)
- Updated comments/description to say there is no **navigation-driven** bUnit test for that exact browser-timing repro.
### Validation
I could not run `dotnet build/test` in this environment because `dotnet` is not installed (`dotnet: command not found`).
ScarletKuro
approved these changes
Feb 28, 2026
This was referenced Mar 3, 2026
This was referenced Mar 4, 2026
Open
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.
Fixes mutation-unsafe async enumeration in
MudMenu:CloseMenuAsync()now snapshots open children beforeawait:_subMenus.Where(...).ToArray()OpenSubMenuAsync()now snapshots open siblings beforeawait:ParentMenu._subMenus.Where(...).ToArray()This prevents
InvalidOperation_EnumFailedVersionwhen child menus unregister/dispose while close recursion is running.Fixes #12741
Checklist: