Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

NavigationLock throws uncaught JSDisconnectedException on Blazor Server #44795

Closed
SteveSandersonMS opened this issue Oct 31, 2022 · 0 comments · Fixed by #44800
Closed

NavigationLock throws uncaught JSDisconnectedException on Blazor Server #44795

SteveSandersonMS opened this issue Oct 31, 2022 · 0 comments · Fixed by #44800
Assignees
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. Servicing-consider Shiproom approval is required for the issue
Milestone

Comments

@SteveSandersonMS
Copy link
Member

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 */ }.

@SteveSandersonMS SteveSandersonMS added the area-blazor Includes: Blazor, Razor Components label Oct 31, 2022
@mkArtakMSFT mkArtakMSFT added the bug This issue describes a behavior which is not expected - a bug. label Oct 31, 2022
@mkArtakMSFT mkArtakMSFT added this to the 7.0.x milestone Oct 31, 2022
@mkArtakMSFT mkArtakMSFT added the Servicing-consider Shiproom approval is required for the issue label Oct 31, 2022
@mkArtakMSFT mkArtakMSFT modified the milestones: 7.0.x, 7.0.1 Nov 1, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Dec 2, 2022
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. Servicing-consider Shiproom approval is required for the issue
Projects
None yet
3 participants