rungwiroon / BlazorGoogleMaps

Blazor interop for GoogleMap library
MIT License
319 stars 102 forks source link

JavaScript interop calls cannot be issued at this time. This is because the circuit has disconnected and is being disposed. #272

Closed ryanbuening closed 1 year ago

ryanbuening commented 1 year ago

In a Blazor Server app, starting with version 3.1.0, we are seeing the exception below in our logs. It seems to occur when a user navigates from a page that includes a map. Is there something that needs done in the component to properly dispose?

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 GoogleMapsComponents.Helper.MyInvokeAsync[TRes](IJSRuntime jsRuntime, String identifier, Object[] args)
   at GoogleMapsComponents.JsObjectRef.InvokeAsync(String functionName, Object[] args)
   at GoogleMapsComponents.Maps.MapEventListener.RemoveAsync()
   at GoogleMapsComponents.Maps.MapEventListener.DisposeAsyncCore()
   at GoogleMapsComponents.Maps.MapEventListener.DisposeAsync()
   at GoogleMapsComponents.Maps.Extension.EventEntityBase.DisposeAsyncCore()
   at GoogleMapsComponents.Maps.Map.DisposeAsyncCore()
   at GoogleMapsComponents.Maps.Map.DisposeAsync()
   at GoogleMapsComponents.MapComponent.DisposeAsyncCore()
   at GoogleMapsComponents.MapComponent.DisposeAsync()
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.<>c__DisplayClass74_0.<<Dispose>g__HandleAsyncExceptions|1>d.MoveNext()
valentasm1 commented 1 year ago

I dont get any error in our server side demo. Maybe you see where is configuration difference? https://github.com/rungwiroon/BlazorGoogleMaps/tree/master/ServerSideDemo

valentasm1 commented 1 year ago

Maybe i need to do some steps to reproduce. Maybe you could reproduce in our server side demo

turner11 commented 1 year ago

Was able to reproduce. Fixed in this PR

valentasm1 commented 1 year ago

Strange issue, strange solution :). https://www.nuget.org/packages/BlazorGoogleMaps/3.1.1

What do you think if we migrate all project from standart to .net6 (or even 7)? There was such ideas for a long time.

turner11 commented 1 year ago

I think it is reasonable enough to do so. Since:

  1. dotnet framework and dotnet core has converged into "dotnet" since version 5.0
  2. The above happend a long time ago.
  3. This aligns with MS announcment

The downsides I can think of are:

  1. legcay user components that relays on this project and targets dotnet standard - I think this project is not popular enough (yet!) for this to be a real consideration.

I have never released a resuable component to Nuget - so take the following with a grain of salt: I think that as a reusable component auther you should target the lowest version that is "modern" and feature rich enogh for you. This will allow your users to use this component, without constraining them to a new version that they might not have migrated to yet. I think in your case this would be .net5.0, possiblly .net6.0.

Also, take a look this section in the linked article. It is very relevnt to this topic.