Repository navigation
Suppress JSDisconnectedException in IJSObjectReference.DisposeAsync - #64773
Merged
Merged
Conversation
Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix IJSObjectReference.Dispose to handle JSDisconnectedException
Suppress JSDisconnectedException in IJSObjectReference.DisposeAsync
Dec 15, 2025
javiercn
marked this pull request as ready for review
December 17, 2025 14:02
pavelsavara
approved these changes
Dec 17, 2025
Contributor
There was a problem hiding this comment.
Pull request overview
This PR enhances the developer experience when working with IJSObjectReference disposal in Blazor Server scenarios by automatically suppressing JSDisconnectedException during disposal operations. The change addresses a common pain point where developers had to manually wrap disposal calls in try-catch blocks to handle circuit disconnections.
Key Changes:
- Modified
JSObjectReference.DisposeAsync()to catch and suppressJSDisconnectedExceptioninternally - Added comprehensive test coverage for both single and multiple disposal attempts with disconnected JS runtime
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/JSInterop/Microsoft.JSInterop/src/Implementation/JSObjectReference.cs |
Added try-catch block in DisposeAsync() to suppress JSDisconnectedException during disposal |
src/JSInterop/Microsoft.JSInterop/test/JSObjectReferenceTest.cs |
Added two test cases and test infrastructure to verify exception suppression behavior |
1 task done
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.
Suppress JSDisconnectedException in IJSObjectReference.DisposeAsync
Catch and discard JSDisconnectedException during JS object disposal
Description
When a circuit disconnects (user navigates away, closes tab, or full-page reload), components disposing
IJSObjectReferenceinstances throwJSDisconnectedException. This forces developers to wrap disposal in try-catch blocks.Changes:
JSObjectReference.DisposeAsync()to catch and suppressJSDisconnectedExceptionRationale:
If JS is disconnected, the JS-side object is already gone. Server-side disposal would fail regardless, so the exception provides no value and only creates noise.
Before:
After:
Original prompt
This section details on the original issue you should resolve
<issue_title>Change IJSObjectReference.Dispose specifically so that it deals with catching and discarding JSDisconnectedException internally</issue_title>
<issue_description>I'm getting a warning and exception when trying to dispose a JavaScript module reference in a component's DisposeAsync method when the component is using the server interactive render mode.
Repro steps:
Expected result: No exception
Actual result: JSDisconnectedException