MudFocusTrap: guard against disposal race in OnAfterRenderAsync#12252
Merged
danielchalmers merged 1 commit intoMudBlazor:devfrom Dec 17, 2025
Merged
MudFocusTrap: guard against disposal race in OnAfterRenderAsync#12252danielchalmers merged 1 commit intoMudBlazor:devfrom
danielchalmers merged 1 commit intoMudBlazor:devfrom
Conversation
ScarletKuro
approved these changes
Dec 12, 2025
EnesEfeTokta
approved these changes
Dec 13, 2025
Member
|
Thank you! |
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 #11862
Problem
MudFocusTrap.OnAfterRenderAsynccan callInitializeFocusAsync()after the component has been disposed which causes an exception. This can happen because awaitSaveFocusAsync()yields; during that await,_disposedmay flip to true, but the method then continues and reaches initialization.Fix
Add a second
_disposedguard after awaitSaveFocusAsync()and before the initialization path. This prevents focus initialization from running after disposal.Repro (reliable)
Insert a temporary delay after
SaveFocusAsync()(e.g.await Task.Delay(3000)), open a dialog and immediately close it (“OK”), then wait—without the extra _disposed check,InitializeFocusAsync()can run post-dispose and crash.Notes
This change only adds a defensive disposal guard; behaviour is unchanged otherwise.
Additional context and analysis