From d45e5b8a211e2c06481050d0f4321a47c8e6ce97 Mon Sep 17 00:00:00 2001 From: Shanewas Ahmed Date: Fri, 18 Sep 2026 10:27:26 +0900 Subject: [PATCH] fix: marshal dialog provider Add/Update onto sync context ShowDialogAsync and UpdateDialogAsync wrapped the References mutation in Task.Run, racing the UI-thread render enumeration and close-path Remove whenever a dialog opened right after another closed. Run both bodies through InvokeAsync instead, matching the sync ShowDialog path. Fixes #5300. --- .../Dialog/FluentDialogProvider.razor.cs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Core/Components/Dialog/FluentDialogProvider.razor.cs b/src/Core/Components/Dialog/FluentDialogProvider.razor.cs index 513cc39cc8..4a901f177c 100644 --- a/src/Core/Components/Dialog/FluentDialogProvider.razor.cs +++ b/src/Core/Components/Dialog/FluentDialogProvider.razor.cs @@ -86,7 +86,7 @@ private void ShowDialog(IDialogReference dialogReference, Type? dialogComponent, private async Task ShowDialogAsync(IDialogReference dialogReference, Type? dialogComponent, DialogParameters parameters, object content) { - return await Task.Run(async () => + await InvokeAsync(async () => { var previouslyFocusedElement = await GetPreviouslyFocusedElementAsync(); @@ -94,10 +94,10 @@ private async Task ShowDialogAsync(IDialogReference dialogRefe dialogReference.Instance = dialog; _internalDialogContext.References.Add(dialogReference); - await InvokeAsync(StateHasChanged); - - return dialogReference; + StateHasChanged(); }); + + return dialogReference; } private void UpdateDialog(string? dialogId, DialogParameters parameters) @@ -116,7 +116,9 @@ private void UpdateDialog(string? dialogId, DialogParameters parameters) private async Task UpdateDialogAsync(string? dialogId, DialogParameters parameters) { - return await Task.Run(() => + IDialogReference? result = null; + + await InvokeAsync(() => { IDialogReference? reference = _internalDialogContext.References.SingleOrDefault(x => x.Id == dialogId)!; DialogInstance? dialogInstance = reference?.Instance; @@ -130,10 +132,13 @@ private void UpdateDialog(string? dialogId, DialogParameters parameters) dialogInstance.Content = content; } - InvokeAsync(StateHasChanged); + StateHasChanged(); } - return reference; + + result = reference; }); + + return result; } // Check if the content object is a IDialogParameters and get the Content property.