-
Notifications
You must be signed in to change notification settings - Fork 99
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
Removed map HTMLElement from DOM still try to render map #335
Comments
Neven create anything in OnInitializedAsync since map load asyn and could be created after this method. Does it works now? |
Funny, I've been banging my head against the wall this afternoon with this exact issue. |
I doublechecked, and to clarify some more points: The proposed implementation works, until the page is refreshed.
Reverting to a single map means the proposed solution works like a charm. |
Do you have sample to reproduce? |
I am working on a reliable one and will report back soon. |
I am loading data that is totally separate from the map, not doing anything with the map in this method. |
@valentasm1 The above commit/fork is a 1:1 repro of the issue, with 100% accuracy. The repro steps were added in a later commit: Steps to reproduce the issue
Note that the solution works perfectly fine when not involving the Mudblazor library, but I wanted to give you a proper repro, as I do think there is room for improvement here. |
I am not conditionally showing or hiding the map in this instance, it should be on the page in load. However, I am using BlazorBootstrap library, so there could be something else going on there as well. I will test some things out when I get some time away from work to get more info and see If i can get a sample. |
For your sanity, I can confirm the proposed solution works fine in NET8, old-school WASM. @if (_myval)
{
<GoogleMap Height="400px" @ref="@_map1" Id="map1" Options="@_mapOptions" OnAfterInit="OnAfterInitAsync" />
}
else
{
<GoogleMap Height="400px" @ref="@_map1" Id="map1" Options="@_mapOptions" OnAfterInit="OnAfterInitAsync" />
} The above code does not cause the issue. Perhaps, like you are indicating, we are both doing something that triggers it. |
MudBlazor has some js listeners on resize. It trigger and remove element from DOM. While OnAfterRenderAsync in MapComponent is already trigered with passing ElementReference. When it reaches js ElementReference dont exist since it was removed from DOM by MudBlazor. I think solution is one line somewhere in code. Just not sure where exactly :). Probably most stupid one is to add check in js, but i dont like it. It smells :). |
This is correct, |
Dirty workaround could be just ovverider js action window.blazorGoogleMaps.objectManager.createObject |
I did kind of hijack @cblanchard-aa 's ticket. My bad :) |
I appreciate you hijacking it! I am busy trying to build an application for my company :). Appreciate the quick response time and turnaround. The issue is resolved on my end, you guys are awesome! Edit - for context - workaround posted in my inital comment is the solution that I am rolling with :) |
Error is thrown when calling Autocomplete.CreateAsync after an async task has been run in the pages OnInitializedAsync method.
Currently you can get around this issue by running your async tasks in the pages OnAfterRenderAsync method.
blazor.web.js:1 [2024-06-17T14:52:34.486Z] Error: Microsoft.JSInterop.JSException: Map: Expected mapDiv of type HTMLElement but was passed null.
InvalidValueError
at _.yj (https://maps.googleapis.com/maps/api/js?libraries=places&key=YOUR_API_KEY&v=weekly&callback=google.maps.__ib__:227:373)
at new Io (https://maps.googleapis.com/maps/api/js?libraries=places&key=YOUR_API_KEY&v=weekly&callback=google.maps.__ib__:298:310)
at Object.createObject (http://localhost:5204/_content/BlazorGoogleMaps/js/objectManager.js:366:27)
at http://localhost:5204/_framework/blazor.web.js:1:3244
at new Promise ()
at y.beginInvokeJSFromDotNet (http://localhost:5204/_framework/blazor.web.js:1:3201)
at gn._invokeClientMethod (http://localhost:5204/_framework/blazor.web.js:1:62841)
at gn._processIncomingData (http://localhost:5204/_framework/blazor.web.js:1:60316)
at connection.onreceive (http://localhost:5204/_framework/blazor.web.js:1:53957)
at i.onmessage (http://localhost:5204/_framework/blazor.web.js:1:82102)
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.CreateAsync(IJSRuntime jsRuntime, Guid guid, String functionName, Object[] args)
at GoogleMapsComponents.Maps.Map.CreateAsync(IJSRuntime jsRuntime, ElementReference mapDiv, MapOptions opts)
at GoogleMapsComponents.MapComponent.InitAsync(ElementReference element, MapOptions options)
at GoogleMapsComponents.GoogleMap.OnAfterRenderAsync(Boolean firstRender)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
The text was updated successfully, but these errors were encountered: