Catch and discard JSDisconnectedException in IJSObjectReference.DisposeAsync for WebView#66259
Draft
Catch and discard JSDisconnectedException in IJSObjectReference.DisposeAsync for WebView#66259
Conversation
…ctReference.DisposeAsync Agent-Logs-Url: https://github.com/dotnet/aspnetcore/sessions/5c277613-66bb-4eea-80d0-9af7bc3e19a6 Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/aspnetcore/sessions/5c277613-66bb-4eea-80d0-9af7bc3e19a6 Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix IJSObjectReference.Dispose to handle JSDisconnectedException
Catch and discard JSDisconnectedException in IJSObjectReference.DisposeAsync for WebView
Apr 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When components dispose
IJSObjectReferenceinstances duringDisposeAsync, aJSDisconnectedExceptioncan be thrown if the JS runtime is no longer available (circuit disconnected, WebView navigated away, or WebView disposed). This is a spurious error — the JS side is already gone, so server-side cleanup of the reference is unnecessary.Description
JSObjectReference.DisposeAsyncalready catches and discardsJSDisconnectedException. This PR extends the same pattern to Blazor WebView:WebViewJSRuntime: Added_disconnectedflag +internal MarkAsDisconnected()method. When set,BeginInvokeJSthrowsJSDisconnectedExceptionimmediately (same pattern asRemoteJSRuntime.MarkPermanentlyDisconnected()).PageContext.DisposeAsync: CallsJSRuntime.MarkAsDisconnected()beforeRenderer.DisposeAsync(), preventing JS interop calls from hanging or throwing during component teardown when the page has navigated away or the WebView is being disposed.Tests: Two new tests verify that the JS runtime is marked disconnected on WebView disposal and on page navigation.