Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

JSInterop error on circuit disposal in .NET 6 #38

Open
smfields opened this issue Dec 4, 2021 · 2 comments
Open

JSInterop error on circuit disposal in .NET 6 #38

smfields opened this issue Dec 4, 2021 · 2 comments

Comments

@smfields
Copy link

smfields commented Dec 4, 2021

Describe the bug
An exception is thrown during the Dispose handler of the IntersectionObserve component when the circuit itself is being disposed.

warn: Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer[100]
      Unhandled exception rendering component: JavaScript interop calls cannot be issued at this time. This is because the circuit has disconnected and is being disposed.
      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 Ljbc1994.Blazor.IntersectionObserver.IntersectionObserverService.RemoveObserver(String id)
         at Ljbc1994.Blazor.IntersectionObserver.IntersectionObserver.Dispose()
         at Ljbc1994.Blazor.IntersectionObserver.Components.IntersectionObserve.DisposeAsync()
         at Microsoft.AspNetCore.Components.RenderTree.Renderer.<>c__DisplayClass69_0.<<Dispose>g__HandleAsyncExceptions|1>d.MoveNext()

Everything still works fine after the exception, but it fills up the error log with unnecessary error messages.

To Reproduce

  1. Create a page that contains the IntersectionObserve component
  2. Refresh or close the page
  3. An exception will be logged to the error logs

Expected behavior
Catch and silently ignore the exception since we don't need to dispose of the observer if the browser is being closed anyway.

System Info

  • Blazor Server
  • .NET 6

Additional context
This was caused by a changed to Blazor that prevents JS Interop actions during circuit disposal: dotnet/aspnetcore#32901

@ljbc1994
Copy link
Owner

ljbc1994 commented Dec 25, 2021

Hi @smfields,

Will look into this when I've got the chance 👍 Thanks for the detailed report this is very helpful

@AndreErb
Copy link

@ljbc1994
Any chance, that a fix for this will come?
We have the same problem and the only thing we can currently do, is suppressing the log by ugly Exception filtering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants