DiscipleTools / disciple-tools-web-components

https://jade-chebakia-17493f.netlify.app/?path=/story/kitchen-sink--kitchen-sink
GNU General Public License v2.0
3 stars 8 forks source link

Google Maps script included multiple times #81

Open cairocoder01 opened 3 months ago

cairocoder01 commented 3 months ago

When showing a dt-location-map field that has multiple geocoded locations as the initial value, console errors are thrown:

You have included the Google Maps JavaScript API multiple times on this page. This may cause unexpected errors.

This is likely because the googleGeocodingService is initialize in the dt-location-map-item, so each location is trying to include the script again. It should probably be included in the parent component and passed down somehow.

There still needs to be some handling in case there are then multiple location components on the page that are pre-populated. The service tries to detect if it's already loaded in the constructor by looking for window.google?.maps?.places?.AutocompleteService, but the script probably isn't loaded by the time the next constructor is called. It would probably be better to check the document for the existence of another script tag with the same source file.