From 45c002993f8bfd8561062a995e74704244cf3106 Mon Sep 17 00:00:00 2001 From: Adam Ratzman Date: Tue, 4 Mar 2025 12:58:09 -0500 Subject: [PATCH] Dispose fluent toolbar module properly --- .../Components/Toolbar/FluentToolbar.razor.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Core/Components/Toolbar/FluentToolbar.razor.cs b/src/Core/Components/Toolbar/FluentToolbar.razor.cs index cb63ffdf1b..b67b646c06 100644 --- a/src/Core/Components/Toolbar/FluentToolbar.razor.cs +++ b/src/Core/Components/Toolbar/FluentToolbar.razor.cs @@ -17,7 +17,7 @@ public partial class FluentToolbar : FluentComponentBase, IAsyncDisposable private IJSRuntime JSRuntime { get; set; } = default!; /// - private IJSObjectReference Module { get; set; } = default!; + private IJSObjectReference? Module { get; set; } /// /// Gets or sets the toolbar's orentation. See @@ -57,10 +57,19 @@ protected override async Task OnAfterRenderAsync(bool firstRender) public async ValueTask DisposeAsync() { - if (Module is not null && !string.IsNullOrEmpty(Id)) + try { - await Module.InvokeVoidAsync("removePreventArrowKeyNavigation", Id); - await Module.DisposeAsync(); + if (Module is not null && !string.IsNullOrEmpty(Id)) + { + await Module.InvokeVoidAsync("removePreventArrowKeyNavigation", Id); + await Module.DisposeAsync(); + } + } + catch (Exception ex) when (ex is JSDisconnectedException || + ex is OperationCanceledException) + { + // The JSRuntime side may routinely be gone already if the reason we're disposing is that + // the client disconnected. This is not an error. } } }