@page-speed/maps 0.2.1 → 0.2.3

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.
@@ -874,9 +874,16 @@ function GeoMap({
874
874
  const updateDimensions = () => {
875
875
  if (containerRef.current) {
876
876
  const rect = containerRef.current.getBoundingClientRect();
877
- setContainerDimensions({
878
- width: rect.width || 800,
879
- height: rect.height || calculatedHeight
877
+ setContainerDimensions((prev) => {
878
+ const newWidth = rect.width || 800;
879
+ const newHeight = rect.height || calculatedHeight;
880
+ if (prev.width === newWidth && prev.height === newHeight) {
881
+ return prev;
882
+ }
883
+ return {
884
+ width: newWidth,
885
+ height: newHeight
886
+ };
880
887
  });
881
888
  }
882
889
  };
@@ -1013,17 +1020,41 @@ function GeoMap({
1013
1020
  const [dynamicPanelPosition, setDynamicPanelPosition] = React3.useState(
1014
1021
  panelPosition
1015
1022
  );
1023
+ const viewStateRef = React3.useRef(uncontrolledViewState);
1016
1024
  React3.useEffect(() => {
1017
1025
  if (!viewState && !defaultViewState) {
1018
- setUncontrolledViewState({
1019
- latitude: firstCoordinate.latitude,
1020
- longitude: firstCoordinate.longitude,
1021
- zoom: calculatedZoom
1026
+ setUncontrolledViewState((prev) => {
1027
+ if (prev.latitude === firstCoordinate.latitude && prev.longitude === firstCoordinate.longitude && prev.zoom === calculatedZoom) {
1028
+ return prev;
1029
+ }
1030
+ return {
1031
+ latitude: firstCoordinate.latitude,
1032
+ longitude: firstCoordinate.longitude,
1033
+ zoom: calculatedZoom
1034
+ };
1022
1035
  });
1023
1036
  }
1024
- }, [firstCoordinate, calculatedZoom, viewState, defaultViewState]);
1037
+ }, [
1038
+ // Use primitive values instead of objects to avoid reference changes
1039
+ firstCoordinate.latitude,
1040
+ firstCoordinate.longitude,
1041
+ calculatedZoom,
1042
+ viewState,
1043
+ defaultViewState
1044
+ ]);
1025
1045
  const isControlledViewState = viewState !== void 0;
1026
1046
  const resolvedViewState = isControlledViewState ? viewState : uncontrolledViewState;
1047
+ React3.useEffect(() => {
1048
+ viewStateRef.current = resolvedViewState || uncontrolledViewState;
1049
+ }, [
1050
+ // Use primitive values to avoid reference changes
1051
+ resolvedViewState?.latitude,
1052
+ resolvedViewState?.longitude,
1053
+ resolvedViewState?.zoom,
1054
+ uncontrolledViewState.latitude,
1055
+ uncontrolledViewState.longitude,
1056
+ uncontrolledViewState.zoom
1057
+ ]);
1027
1058
  const applyViewState = React3.useCallback(
1028
1059
  (nextState) => {
1029
1060
  if (!isControlledViewState) {
@@ -1062,7 +1093,13 @@ function GeoMap({
1062
1093
  setSelection({ type: "none" });
1063
1094
  onSelectionChange?.({ type: "none" });
1064
1095
  }
1065
- }, [onSelectionChange, selectedMarker, selection]);
1096
+ }, [
1097
+ // Use primitive values to avoid object reference issues
1098
+ selection.type,
1099
+ selection.markerId,
1100
+ selectedMarker?.id,
1101
+ onSelectionChange
1102
+ ]);
1066
1103
  const emitSelectionChange = React3.useCallback(
1067
1104
  (nextSelection) => {
1068
1105
  if (nextSelection.type === "none") {
@@ -1092,17 +1129,15 @@ function GeoMap({
1092
1129
  markerId: marker.id,
1093
1130
  clusterId: marker.clusterId
1094
1131
  });
1095
- const currentCenter = resolvedViewState || {
1096
- latitude: firstCoordinate.latitude,
1097
- longitude: firstCoordinate.longitude
1132
+ const currentState = viewStateRef.current;
1133
+ const center = {
1134
+ latitude: currentState.latitude ?? 0,
1135
+ longitude: currentState.longitude ?? 0
1098
1136
  };
1099
1137
  const optimalPosition = getOptimalPanelPosition(
1100
1138
  marker.latitude,
1101
1139
  marker.longitude,
1102
- {
1103
- latitude: currentCenter.latitude ?? firstCoordinate.latitude,
1104
- longitude: currentCenter.longitude ?? firstCoordinate.longitude
1105
- }
1140
+ center
1106
1141
  );
1107
1142
  setDynamicPanelPosition(optimalPosition);
1108
1143
  applyViewState({
@@ -1112,7 +1147,7 @@ function GeoMap({
1112
1147
  });
1113
1148
  emitSelectionChange({ type: "marker", marker });
1114
1149
  },
1115
- [applyViewState, emitSelectionChange, markerFocusZoom, resolvedViewState, firstCoordinate]
1150
+ [applyViewState, emitSelectionChange, markerFocusZoom]
1116
1151
  );
1117
1152
  const selectCluster = React3.useCallback(
1118
1153
  (cluster) => {
@@ -1120,17 +1155,15 @@ function GeoMap({
1120
1155
  type: "cluster",
1121
1156
  clusterId: cluster.id
1122
1157
  });
1123
- const currentCenter = resolvedViewState || {
1124
- latitude: firstCoordinate.latitude,
1125
- longitude: firstCoordinate.longitude
1158
+ const currentState = viewStateRef.current;
1159
+ const center = {
1160
+ latitude: currentState.latitude ?? 0,
1161
+ longitude: currentState.longitude ?? 0
1126
1162
  };
1127
1163
  const optimalPosition = getOptimalPanelPosition(
1128
1164
  cluster.latitude,
1129
1165
  cluster.longitude,
1130
- {
1131
- latitude: currentCenter.latitude ?? firstCoordinate.latitude,
1132
- longitude: currentCenter.longitude ?? firstCoordinate.longitude
1133
- }
1166
+ center
1134
1167
  );
1135
1168
  setDynamicPanelPosition(optimalPosition);
1136
1169
  applyViewState({
@@ -1140,7 +1173,7 @@ function GeoMap({
1140
1173
  });
1141
1174
  emitSelectionChange({ type: "cluster", cluster });
1142
1175
  },
1143
- [applyViewState, clusterFocusZoom, emitSelectionChange, resolvedViewState, firstCoordinate]
1176
+ [applyViewState, clusterFocusZoom, emitSelectionChange]
1144
1177
  );
1145
1178
  const clearSelection = React3.useCallback(() => {
1146
1179
  setSelection({ type: "none" });