Skip to content

Commit 79694a9

Browse files
authored
Fix a timing issue for sequential importLibrary calls
Works around googlemaps#809
1 parent 959ea63 commit 79694a9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,11 @@ export class Loader {
469469
name: "visualization"
470470
): Promise<google.maps.VisualizationLibrary>;
471471
public importLibrary(name: Library): Promise<unknown>;
472-
public importLibrary(name: Library): Promise<unknown> {
472+
public async importLibrary(name: Library): Promise<unknown> {
473473
this.execute();
474-
return google.maps.importLibrary(name);
474+
// Extra await here works around https://github.com/googlemaps/js-api-loader/issues/809.
475+
// This is kind of an icky timing workaround, but the issue really is that user code after importLibrary is getting invoked 1 microtask before the library code handles the completion.
476+
return await google.maps.importLibrary(name);
475477
}
476478

477479
/**
@@ -629,7 +631,7 @@ export class Loader {
629631
// short circuit and warn if google.maps is already loaded
630632
if (window.google && window.google.maps && window.google.maps.version) {
631633
console.warn(
632-
"Google Maps already loaded outside @googlemaps/js-api-loader." +
634+
"Google Maps already loaded outside @googlemaps/js-api-loader. " +
633635
"This may result in undesirable behavior as options and script parameters may not match."
634636
);
635637
this.callback();

0 commit comments

Comments
 (0)