Skip to content

NavigationLock throws uncaught JSDisconnectedException on Blazor Server #44795

@SteveSandersonMS

Description

@SteveSandersonMS

Scenario:

  1. Use Blazor Server
  2. Add <NavigationLock ConfirmExternalNavigation="true" /> to any page
  3. Go there, then either do an external navigation and click "Leave" to confirm it, or even just close the browser tab directly

Expected: No exception

Actual: Logs to server console:

fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
      Unhandled exception in circuit '__YJjLKu09bxilqrSj052d-Jv_H5M5SgQAJWer3i7-0'.
      Microsoft.JSInterop.JSDisconnectedException: JavaScript interop calls cannot be issued at this time. This is because the circuit has disconnected and is being disposed.
         at Microsoft.AspNetCore.Components.Server.Circuits.RemoteJSRuntime.BeginInvokeJS(Int64 asyncHandle, String identifier, String argsJson, JSCallResultType resultType, Int64 targetInstanceId)
         at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, CancellationToken cancellationToken, Object[] args)
         at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args)
         at Microsoft.JSInterop.JSRuntimeExtensions.InvokeVoidAsync(IJSRuntime jsRuntime, String identifier, Object[] args)
         at Microsoft.AspNetCore.Components.Routing.NavigationLock.System.IAsyncDisposable.DisposeAsync()
         at Microsoft.AspNetCore.Components.RenderTree.Renderer.<>c__DisplayClass74_0.<<Dispose>g__HandleAsyncExceptions|1>d.MoveNext()

Reason

Looks like this is simply because we do this JS interop call during DisposeAsync without catching the JSDisconnectedException.

Suggested fix

We should wrap that JS invocation in a try { ... } catch (JSDisconnectedException) { /* ignored */ }.

Metadata

Metadata

Assignees

Labels

Servicing-considerShiproom approval is required for the issuearea-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions