-
Notifications
You must be signed in to change notification settings - Fork 83
Description
🐛 The bug
Using a simple setup with the Google Maps SFC components I found out that the markers do not get cleaned resulting in detached markers.
<ScriptGoogleMaps
:apiKey="$config.public.google.mapsApiKey"
:center="center"
:mapOptions="{ zoom: zoom }"
:class="['h-full w-full', { 'overflow-hidden rounded-2xl': isSingle }]"
aboveTheFold
trigger="immediate"
width="100%"
height="100%"
>
<ScriptGoogleMapsAdvancedMarkerElement
v-for="location in locations"
:key="location.id"
:options="{
position: {
lat: location.latitude,
lng: location.longitude
}
}">
</ScriptGoogleMapsAdvancedMarkerElement>
</ScriptGoogleMaps>
In the memory profiler I was able to confirm that the memory stayed about the same when leaving the page with the map component. When navigating back and forth to the maps page and the home page it kept stacking up, eventually leading to a heap out of memory crash.
Snapshot 24 is a snapshot on the maps page and snapshot 25 is on the home page with a forced garbage collection.
My assumption is that the creation of the markers is async and doesn't work well with the component unmount lifecycle. So the following would happen:
- Component mounts and starts async process to create marker.
- Component unmounts because of a re-render for example. Although I was able to trigger this on load as well. Marker does not exist yet so cleanup does nothing.
- The marker gets created and added to the map after unmounting.
- No component owns it anymore and won't be cleaned up.
🛠️ To reproduce
See above, could not get an example to load google maps
🌈 Expected behavior
The markers are properly cleaned up instead of becoming detached elements.
ℹ️ Additional context
Using Nuxt 4.3.1 and Nuxt Scripts 1.0.0-beta.19