Skip to content

Commit 27496ab

Browse files
authored
Add missing try..catch in DisposeAsync (#3699)
1 parent 838225d commit 27496ab

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

src/Core/Components/List/FluentCombobox.razor.cs

+13-4
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,20 @@ protected override async Task ChangeHandlerAsync(ChangeEventArgs e)
177177

178178
public new async ValueTask DisposeAsync()
179179
{
180-
if (Module is not null && !string.IsNullOrEmpty(Id))
180+
try
181181
{
182-
await Module.InvokeVoidAsync("detachIndicatorClickHandler", Id);
183-
await Module.DisposeAsync();
182+
if (Module is not null && !string.IsNullOrEmpty(Id))
183+
{
184+
await Module.InvokeVoidAsync("detachIndicatorClickHandler", Id);
185+
await Module.DisposeAsync();
186+
}
187+
await base.DisposeAsync();
188+
}
189+
catch (Exception ex) when (ex is JSDisconnectedException ||
190+
ex is OperationCanceledException)
191+
{
192+
// The JSRuntime side may routinely be gone already if the reason we're disposing is that
193+
// the client disconnected. This is not an error.
184194
}
185-
await base.DisposeAsync();
186195
}
187196
}

src/Core/Components/Overlay/FluentOverlay.razor.cs

+13-3
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,21 @@ private async Task OnCloseInternalHandlerAsync(MouseEventArgs e)
266266
/// <returns></returns>
267267
public async ValueTask DisposeAsync()
268268
{
269-
await InvokeOverlayDisposeAsync();
269+
try
270+
{
271+
await InvokeOverlayDisposeAsync();
272+
273+
if (_jsModule != null)
274+
{
275+
await _jsModule.DisposeAsync();
276+
}
270277

271-
if (_jsModule != null)
278+
}
279+
catch (Exception ex) when (ex is JSDisconnectedException ||
280+
ex is OperationCanceledException)
272281
{
273-
await _jsModule.DisposeAsync();
282+
// The JSRuntime side may routinely be gone already if the reason we're disposing is that
283+
// the client disconnected. This is not an error.
274284
}
275285

276286
GlobalState.OnChange -= UpdateNeutralColor;

0 commit comments

Comments
 (0)