Skip to content

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

Description

@DzmVasileusky

Steps to reproduce and a minimal demo

The problem happens when you may need to load google maps API for other library purpose before the ngui-map will add it.
ngui-map doesn't check if the API is already added and add it second time.
Which results to
You have included the Google Maps JavaScript API multiple times on this page. This may cause unexpected errors.

To reproduce just add google maps API manually in the head of the page.
UPD
This is happening from time to time and only with
NgMapAsyncCallbackApiLoader. If NgMapAsyncApiLoader is adding the script it is ok.
I found out the culprit:
isMapsApiLoaded are checking only already loaded google API but it isn't checkin loading one.
So if another library will add script dynamically - it may be not ready in the time isMapsApiLoaded is called.

Current behavior

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

Expected/desired behavior

Library is checking for the google maps API to be already added and loaded and not add it again.
We are using this code to check if it is ready

export const googleMapsApiAdded = () => {

    return document.querySelectorAll('script[src*="maps.google.com/maps/api/js"]').length > 0;

};

export const googleMapsApiLoaded = () => {

    return typeof google === 'object' && typeof google.maps === 'object';

};

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions