-
Notifications
You must be signed in to change notification settings - Fork 64
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
Loader reports warning when using importLibrary multiple times #809
Comments
Any updates on this issue, I have been facing the same issue for a while now. Also, could be related to this: seems like even if we specify a particular library name, it still returns the whole payload i.e. having the following
still loads and populates every library, as if we had called the deprecated |
FWIW I found this example of loading multiple libraries here: https://cloud.google.com/blog/products/maps-platform/more-control-loading-maps-javascript-api |
Hi @usefulthink, The assistance from @venatiodecorus was incredibly useful in this context. Regarding the implementation, you can leverage Promise.all to efficiently load your libraries concurrently. Here's how you could do it: const [mapLibrary, markerLibrary] = await Promise.all([
loader.importLibrary('maps'),
loader.importLibrary('marker')
]); This code will allow you to import both maps and marker libraries in parallel, which can help streamline your setup process. Best regards! |
This bug is related to this line https://github.com/googlemaps/js-api-loader/blob/main/src/index.ts#L630 Threre is no check if specific library is loaded, this check is uselles if libraries are imported one by one. |
Fix: Promise.all() instead await for every importLibrary.
|
So this is an interesting race condition bug that I think only happens with two back-to-back Though for what it's worth, even after this bug is fixed I would recommend using Promise.all() [edit: instead of back-to-back |
const { Map } = await loader.importLibrary("maps");
const showPlaces = async (places) => {
const { Autocomplete } = await loader.importLibrary("places");
// ...
}; |
@Profesor08 Yes, that's true. You will need to call Promise.all() first and then access the variables later. Something like this.
|
Maybe in future we could pass an array of Libraries instead 1 library in You can use Or if using react then you can simply define them in a Context and share the libraries as props to nested components. |
When loading the maps library followed by another library using
loader.importLibrary()
and async/await syntax, a misleading warning-message"Google Maps already loaded outside @googlemaps/js-api-loader.This may result in undesirable behavior as options and script parameters may not match."
is written to the console.Here's the code that triggers this behavior:
The reason appears to be that the
done
flag isn't correctly set totrue
after the maps-api has initially been loaded.The text was updated successfully, but these errors were encountered: