Skip to content

Commit 06cfc19

Browse files
[InputFile] Better handling of dispose error. (microsoft#3605)
* Swallow the JSDisconnectedException when trying to call the 'dispose' Javascript method. * All items in dispose will fail if the circuit is closed. Wrap the try/catch around all items. * Updated per comments.
1 parent 4c9eb18 commit 06cfc19

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/Core/Components/InputFile/FluentInputFile.razor.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public partial class FluentInputFile : FluentComponentBase, IAsyncDisposable
1212
private ElementReference? _containerElement;
1313
private InputFile? _inputFile;
1414
private IJSObjectReference? _containerInstance;
15-
15+
1616
public static string ResourceLoadingBefore = "Loading...";
1717
public static string ResourceLoadingCompleted = "Completed";
1818
public static string ResourceLoadingCanceled = "Canceled";
@@ -427,15 +427,24 @@ private async Task UpdateProgressAsync(int percent, string title)
427427
// Unregister the drop zone events
428428
public async ValueTask DisposeAsync()
429429
{
430-
if (_containerInstance != null)
430+
try
431431
{
432-
await _containerInstance.InvokeVoidAsync("dispose");
433-
await _containerInstance.DisposeAsync();
434-
}
432+
if (_containerInstance is not null)
433+
{
434+
await _containerInstance.InvokeVoidAsync("dispose");
435+
await _containerInstance.DisposeAsync().ConfigureAwait(false);
436+
}
435437

436-
if (Module != null)
438+
if (Module != null)
439+
{
440+
await Module.DisposeAsync().ConfigureAwait(false);
441+
}
442+
}
443+
catch (Exception ex) when (ex is JSDisconnectedException ||
444+
ex is OperationCanceledException)
437445
{
438-
await Module.DisposeAsync();
446+
// The JSRuntime side may routinely be gone already if the reason we're disposing is that
447+
// the client disconnected. This is not an error.
439448
}
440449
}
441450
}

0 commit comments

Comments
 (0)