Skip to content

Commit 43e5802

Browse files
Fix google-map-react#954: Use single instance of Loader (google-map-react#968)
* Use single instance of Loader * Update @googlemaps/js-api-loader
1 parent a1d54dd commit 43e5802

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"deploy": "gh-pages -d example/build"
2828
},
2929
"dependencies": {
30-
"@googlemaps/js-api-loader": "^1.4.0",
30+
"@googlemaps/js-api-loader": "^1.7.0",
3131
"@mapbox/point-geometry": "^0.1.0",
3232
"eventemitter3": "^4.0.4",
3333
"prop-types": "^15.7.2"
@@ -50,8 +50,8 @@
5050
"eslint-plugin-react": "^7.17.0",
5151
"eslint-plugin-standard": "^4.0.1",
5252
"expect": "1.20.2",
53-
"jsdom": "^6.5.1",
5453
"gh-pages": "^2.2.0",
54+
"jsdom": "^6.5.1",
5555
"microbundle-crl": "^0.13.10",
5656
"npm-run-all": "^4.1.5",
5757
"prettier": "^2.0.4",

src/loaders/google_map_loader.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Loader } from '@googlemaps/js-api-loader';
22

3+
let loader_;
34
let loadPromise_;
45
let resolveCustomPromise_;
56

@@ -56,12 +57,15 @@ export default (bootstrapURLKeys, heatmapLibrary) => {
5657

5758
const { key, ...restKeys } = bootstrapURLKeys;
5859

59-
const loader_ = new Loader({
60-
// need to keep key for backwards compatibility
61-
apiKey: key || '',
62-
...restKeys,
63-
libraries,
64-
});
60+
// use single instance of Loader to avoid multiple api loads
61+
if (!loader_) {
62+
loader_ = new Loader({
63+
// need to keep key as a prop for backwards compatibility
64+
apiKey: key || '',
65+
...restKeys,
66+
libraries,
67+
});
68+
}
6569

6670
loadPromise_ = loader_.load().then(() => {
6771
resolveCustomPromise_(window.google.maps);

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,10 +1199,10 @@
11991199
resolved "https://registry.yarnpkg.com/@csstools/normalize.css/-/normalize.css-10.1.0.tgz#f0950bba18819512d42f7197e56c518aa491cf18"
12001200
integrity sha512-ij4wRiunFfaJxjB0BdrYHIH8FxBJpOwNPhhAcunlmPdXudL1WQV1qoP9un6JsEBAgQH+7UXyyjh0g7jTxXK6tg==
12011201

1202-
"@googlemaps/js-api-loader@^1.4.0":
1203-
version "1.4.0"
1204-
resolved "https://registry.yarnpkg.com/@googlemaps/js-api-loader/-/js-api-loader-1.4.0.tgz#2dcfc22c25fb295596046c3120d870de686aae77"
1205-
integrity sha512-WVGfV0AINBFdpBt+qgtQe2H2KWDpH0snXTeIZID2YgGo5bSNKxjaFqiw96Ma19oupTWr9B1ud+6j4xhHe/BMWA==
1202+
"@googlemaps/js-api-loader@^1.7.0":
1203+
version "1.7.0"
1204+
resolved "https://registry.yarnpkg.com/@googlemaps/js-api-loader/-/js-api-loader-1.7.0.tgz#d134f4a1bb8d1d864a5da41329da67b192acfa6b"
1205+
integrity sha512-6DkHnfFh81qcez8j8CEG8C3ANvA+3dbOzo8Hg9/DuNI78h36ILquUUuwUG6JHiRvPbqBG146rLDFSympUuO+6Q==
12061206

12071207
"@hapi/address@2.x.x":
12081208
version "2.1.4"

0 commit comments

Comments
 (0)