Skip to content

Commit 2b13ad9

Browse files
authored
feat: abort if google.maps.version defined (#81)
1 parent f2d533a commit 2b13ad9

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/index.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,12 @@ test("setScript adds a nonce", () => {
155155
const script = document.head.childNodes[0] as HTMLScriptElement;
156156
expect(script.nonce).toBe(nonce);
157157
});
158+
159+
test("loader should resolve immediately when google.maps defined", async () => {
160+
const loader = new Loader({ apiKey: "foo" });
161+
window.google = { maps: { version: "3.*.*" } as any };
162+
console.warn = jest.fn();
163+
await expect(loader.loadPromise()).resolves.toBeUndefined();
164+
delete window.google;
165+
expect(console.warn).toHaveBeenCalledTimes(1);
166+
});

src/index.ts

+8
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,14 @@ export class Loader {
398398
}
399399

400400
private execute(): void {
401+
if (window.google && window.google.maps && window.google.maps.version) {
402+
console.warn(
403+
"Aborted attempt to load Google Maps JS with @googlemaps/js-api-loader." +
404+
"This may result in undesirable behavior as script parameters may not match."
405+
);
406+
this.callback();
407+
}
408+
401409
if (this.done) {
402410
this.callback();
403411
} else {

0 commit comments

Comments
 (0)