Skip to content
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

Console warning: "Google Maps JavaScript API has been loaded directly without loading=async" #232

Open
simka1911 opened this issue Feb 29, 2024 · 2 comments

Comments

@simka1911
Copy link

When using usePlacesWidget hook, a warning is shown in the console:

Google Maps JavaScript API has been loaded directly without loading=async. This can result in suboptimal performance.

Is it possible to add async attribute to script during loadGoogleMapScript execution?

google-maps-async-warning
@SamLeatherdale
Copy link

The recommendations in Google's docs on Loading the Maps JavaScript API don't even recommend a script tag anymore, they recommend using the @googlemaps/js-api-loader package.

@bruno-agileengine
Copy link

bruno-agileengine commented Apr 23, 2024

It seems this issue comes from googleMapsScriptUrl inside usePlacesAutocompleteService.ts

export default function usePlacesAutocompleteService({
  apiKey,
  libraries = "places",
  googleMapsScriptBaseUrl = GOOGLE_MAP_SCRIPT_BASE_URL,
  debounce = 300,
  options = {},
  sessionToken,
  language,
}) {
  const languageQueryParam = language ? `&language=${language}` : "";
  const googleMapsScriptUrl = `${googleMapsScriptBaseUrl}?key=${apiKey}&libraries=${libraries}${languageQueryParam}`;

I tried adding loading=async to googleMapsScriptUrl and the warning disappeared, but then I got this error

image

usePlacesAutocompleteService.js:110 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'AutocompleteService') at buildService (usePlacesAutocompleteService.js:110:66) at eval (usePlacesAutocompleteService.js:118:16)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants