[Menu] Unregister disposed menu instances - #5035
Merged
Merged
Conversation
Unregister service-backed menus during disposal and notify the provider after successful removal. Add lifecycle regression coverage for registration, idempotency, and duplicate IDs. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8541ad78-5e1c-4374-a3a5-7482a945eb69
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a lifecycle leak in the menu system by ensuring FluentMenu instances registered into the scoped IMenuService are properly unregistered during disposal, allowing provider render state and captured component graphs to be released for the circuit lifetime.
Changes:
- Track the exact
IMenuServiceinstance used to register aFluentMenu, and unregister it inFluentMenu.DisposeAsync()before JS cleanup. - Update
MenuService.Removeto remove the exact component instance (not “first by Id”) and only notify the provider when a removal actually occurs (idempotent repeat disposal). - Add unit tests covering unregister-on-dispose, idempotent repeated disposal, and duplicate-ID isolation.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/Core/_ToDo/Menu/FluentMenuTests.razor.cs | Adds coverage for registration/unregistration behavior and provider notification semantics during disposal. |
| src/Core/Components/Menu/Services/MenuService.cs | Makes removal instance-precise and only invokes OnMenuUpdated when a removal succeeds. |
| src/Core/Components/Menu/FluentMenu.razor.cs | Tracks the registering service and unregisters from it during DisposeAsync before JS resource disposal. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
vnbaaij
approved these changes
Jul 21, 2026
This was referenced Jul 30, 2026
Open
Open
Open
Closed
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.
Pull Request
📖 Description
FluentMenuregistered service-backed instances during initialization but never called the existingIMenuService.Removeoperation during disposal. The scoped service therefore retained disposed menus, including their render fragments, callbacks, and parent component state, for the circuit lifetime.This change tracks the exact service instance that accepted each registration and unregisters the menu before disposing JavaScript resources.
MenuService.Removenow removes the exact component instance and notifies the provider only when removal succeeds, keeping repeated disposal idempotent and allowing provider render state to release the menu.🎫 Issues
Fixes #5032
👩💻 Reviewer Notes
Please focus on the service-backed menu lifecycle in
FluentMenu.DisposeAsyncand the successful-removal notification inMenuService.Remove.No smoke test is required; the regression is covered at the component/service lifecycle boundary.
📑 Test Plan
dotnet test tests\Core\Microsoft.FluentUI.AspNetCore.Components.Tests.csproj --no-restore --filter "FullyQualifiedName~Microsoft.FluentUI.AspNetCore.Components.Tests.Menu.FluentMenuTests" --verbosity minimal✅ Checklist
General
Component-specific
⏭ Next Steps
None.