@revivejs/react-google-maps 19.0.0 → 19.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  **[Documentation & Live Demos](https://alexandroit.github.io/react-google-maps/)** | **[npm](https://www.npmjs.com/package/@revivejs/react-google-maps)** | **[Issues](https://github.com/alexandroit/react-google-maps/issues)** | **[Repository](https://github.com/alexandroit/react-google-maps)**
12
12
 
13
- **Latest version:** `19.0.0`
13
+ **Latest version:** `19.0.1`
14
14
 
15
15
  ## Why this library?
16
16
 
@@ -39,9 +39,9 @@ That means you can keep a typed React API for the 90% case and still drop to nat
39
39
 
40
40
  | Package version | React version | Google Maps support | Demo link |
41
41
  | :---: | :---: | :---: | :--- |
42
- | **19.0.0** | **19.2.x** | Maps, markers, advanced markers, clustering, shapes, layers, directions, geocoder | [React 19 demo](https://alexandroit.github.io/react-google-maps/react-19/) |
43
- | **18.0.0** | **18.3.x** | Maps, markers, advanced markers, clustering, shapes, layers, directions, geocoder | [React 18 demo](https://alexandroit.github.io/react-google-maps/react-18/) |
44
- | **17.0.0** | **17.0.x** | Maps, markers, advanced markers, clustering, shapes, layers, directions, geocoder | [React 17 demo](https://alexandroit.github.io/react-google-maps/react-17/) |
42
+ | **19.0.1** | **19.2.x** | Maps, markers, advanced markers, clustering, shapes, layers, directions, geocoder | [React 19 demo](https://alexandroit.github.io/react-google-maps/react-19/) |
43
+ | **18.0.1** | **18.3.x** | Maps, markers, advanced markers, clustering, shapes, layers, directions, geocoder | [React 18 demo](https://alexandroit.github.io/react-google-maps/react-18/) |
44
+ | **17.0.1** | **17.0.x** | Maps, markers, advanced markers, clustering, shapes, layers, directions, geocoder | [React 17 demo](https://alexandroit.github.io/react-google-maps/react-17/) |
45
45
 
46
46
  ## Installation
47
47
 
package/dist/index.cjs CHANGED
@@ -67,7 +67,7 @@ function useGoogleMapsApiContext() {
67
67
  }
68
68
 
69
69
  // src/loadGoogleMapsApi.ts
70
- var DEFAULT_LIBRARIES = ["marker", "places", "geometry", "visualization"];
70
+ var DEFAULT_LIBRARIES = [];
71
71
  var loaderPromise = null;
72
72
  var loadedOptionsKey = null;
73
73
  function getDefaultGoogleMapsLibraries() {
@@ -77,9 +77,6 @@ function loadGoogleMapsApi(options) {
77
77
  if (typeof window === "undefined" || typeof document === "undefined") {
78
78
  return Promise.reject(new Error("@revivejs/react-google-maps can only load the Google Maps API in a browser environment."));
79
79
  }
80
- if (!options.apiKey) {
81
- return Promise.reject(new Error("A Google Maps API key is required to load the Google Maps JavaScript API."));
82
- }
83
80
  if (window.google?.maps) {
84
81
  return Promise.resolve(window.google);
85
82
  }
@@ -109,7 +106,7 @@ function loadGoogleMapsApi(options) {
109
106
  return;
110
107
  }
111
108
  const params = new URLSearchParams();
112
- params.set("key", normalizedOptions.apiKey);
109
+ params.set("key", normalizedOptions.apiKey ?? "");
113
110
  params.set("v", normalizedOptions.version);
114
111
  params.set("loading", "async");
115
112
  params.set("callback", callbackName);
@@ -184,12 +181,6 @@ function GoogleMapsProvider({ children, ...options }) {
184
181
  });
185
182
  (0, import_react2.useEffect)(() => {
186
183
  let cancelled = false;
187
- if (!options.apiKey) {
188
- setStatus("idle");
189
- setError(null);
190
- setGoogleApi(null);
191
- return;
192
- }
193
184
  setStatus((current) => current === "ready" ? current : "loading");
194
185
  setError(null);
195
186
  loadGoogleMapsApi(options).then((googleNamespace) => {
@@ -422,8 +413,13 @@ var GoogleMap = (0, import_react4.forwardRef)(function GoogleMap2({
422
413
  }, ref) {
423
414
  const { isLoaded, status, error, google: google2 } = useGoogleMapsApi();
424
415
  const containerRef = (0, import_react4.useRef)(null);
416
+ const mapRef = (0, import_react4.useRef)(null);
417
+ const onMapLoadRef = (0, import_react4.useRef)(onMapLoad);
418
+ const onMapUnmountRef = (0, import_react4.useRef)(onMapUnmount);
425
419
  const [map, setMap] = (0, import_react4.useState)(null);
426
420
  const initialMapIdRef = (0, import_react4.useRef)(mapId);
421
+ onMapLoadRef.current = onMapLoad;
422
+ onMapUnmountRef.current = onMapUnmount;
427
423
  (0, import_react4.useImperativeHandle)(
428
424
  ref,
429
425
  () => ({
@@ -492,7 +488,7 @@ var GoogleMap = (0, import_react4.forwardRef)(function GoogleMap2({
492
488
  [map]
493
489
  );
494
490
  (0, import_react4.useEffect)(() => {
495
- if (!isLoaded || !google2 || !containerRef.current || map) {
491
+ if (!isLoaded || !google2 || !containerRef.current || mapRef.current) {
496
492
  return;
497
493
  }
498
494
  const nextMap = new google2.maps.Map(
@@ -503,13 +499,16 @@ var GoogleMap = (0, import_react4.forwardRef)(function GoogleMap2({
503
499
  mapId: initialMapIdRef.current
504
500
  })
505
501
  );
502
+ mapRef.current = nextMap;
506
503
  setMap(nextMap);
507
- onMapLoad?.(nextMap);
504
+ onMapLoadRef.current?.(nextMap);
508
505
  return () => {
509
- onMapUnmount?.(nextMap);
506
+ google2.maps.event.clearInstanceListeners(nextMap);
507
+ onMapUnmountRef.current?.(nextMap);
508
+ mapRef.current = null;
510
509
  setMap(null);
511
510
  };
512
- }, [isLoaded, google2, map]);
511
+ }, [isLoaded, google2]);
513
512
  (0, import_react4.useEffect)(() => {
514
513
  if (!map) {
515
514
  return;
@@ -670,7 +669,12 @@ var MapMarker = (0, import_react5.forwardRef)(function MapMarker2({
670
669
  }, ref) {
671
670
  const map = useGoogleMap();
672
671
  const clustererContext = (0, import_react5.useContext)(MarkerClustererContext);
672
+ const markerRef = (0, import_react5.useRef)(null);
673
+ const onLoadRef = (0, import_react5.useRef)(onLoad);
674
+ const onUnmountRef = (0, import_react5.useRef)(onUnmount);
673
675
  const [marker, setMarker] = (0, import_react5.useState)(null);
676
+ onLoadRef.current = onLoad;
677
+ onUnmountRef.current = onUnmount;
674
678
  (0, import_react5.useImperativeHandle)(
675
679
  ref,
676
680
  () => ({
@@ -724,18 +728,22 @@ var MapMarker = (0, import_react5.forwardRef)(function MapMarker2({
724
728
  [marker]
725
729
  );
726
730
  (0, import_react5.useEffect)(() => {
727
- if (!map || marker) {
731
+ if (!map || markerRef.current) {
728
732
  return;
729
733
  }
730
734
  const instance = new google.maps.Marker();
735
+ markerRef.current = instance;
731
736
  setMarker(instance);
732
- onLoad?.(instance);
737
+ onLoadRef.current?.(instance);
733
738
  return () => {
734
- onUnmount?.(instance);
739
+ google.maps.event.clearInstanceListeners(instance);
740
+ onUnmountRef.current?.(instance);
735
741
  clustererContext?.unregisterMarker(instance);
736
742
  instance.setMap(null);
743
+ markerRef.current = null;
744
+ setMarker(null);
737
745
  };
738
- }, [map, marker]);
746
+ }, [map, clustererContext]);
739
747
  (0, import_react5.useEffect)(() => {
740
748
  if (!marker || !map) {
741
749
  return;