Prevent JS interop after circuit disposal. Fixes #32808#32901
Conversation
mkArtakMSFT
left a comment
There was a problem hiding this comment.
Thanks @SteveSandersonMS!
|
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
Co-authored-by: Pranav K <prkrishn@hotmail.com>
Co-authored-by: Pranav K <prkrishn@hotmail.com>
Co-authored-by: Tanay Parikh <TanayParikh@users.noreply.github.com>
javiercn
left a comment
There was a problem hiding this comment.
Changes look great!
Do we need to do anything for calls that might already be in-flight?
I considered it, but didn't think it was desirable because: (1) it's not required to solve any known problem (the call will eventually time out anyway, and isn't keeping the circuit open) Overall since it's not required to solve the current problem here, I wasn't inclined to expand the scope of the solution. We could do it in the future if a sufficient need arises. |
|
Hello @SteveSandersonMS, I am using the sample from the #32808 (comment) issue with .NET v5.0.6. Assume, I'm developing a custom Will this code break under .NET 6? Thanks, |
|
Hi @pos777. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context. |

See more details about the problem at #32808 (comment). In summary, any component that attempts JS interop during disposal (for example,
<Virtualize>) would hang until the JS call times out, preventing cleanup of any scoped resources for that period.This PR changes how JS interop works after a circuit has begun disposal (which typically means the user has closed their browser tab or navigated away):
JSDisconnectedException)I think we can regard this as not a breaking change because the calls would have eventually thrown anyway, and still do. It now just completes this process faster. The advantages of this change are:
<Virtualize>component and the user closes the tab). They now clean up immediately.Virtualizeso it won't even get logged as an error. This makes sense in cases where you were only trying to do JS interop to clean up browser-side state, and obviously don't care about that if the browser is already gone.If we wanted, we could consider more dramatic options like:
JSDisconnectedExceptionentirely from logs. I think that's a bad idea because it likely prevents developers from discovering that one was even happening. And then if their disposal logic looked likeDoJsCleanUp(); DoDotNetCleanUp();, they would not realise that theDoDotNetCleanUppart never executes. I think developers need to know this is an error and it's up to them to try/catch if they want to control how it's handled.