@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.
@@ -895,9 +895,16 @@ function GeoMap({
895
895
  const updateDimensions = () => {
896
896
  if (containerRef.current) {
897
897
  const rect = containerRef.current.getBoundingClientRect();
898
- setContainerDimensions({
899
- width: rect.width || 800,
900
- height: rect.height || calculatedHeight
898
+ setContainerDimensions((prev) => {
899
+ const newWidth = rect.width || 800;
900
+ const newHeight = rect.height || calculatedHeight;
901
+ if (prev.width === newWidth && prev.height === newHeight) {
902
+ return prev;
903
+ }
904
+ return {
905
+ width: newWidth,
906
+ height: newHeight
907
+ };
901
908
  });
902
909
  }
903
910
  };
@@ -1034,17 +1041,41 @@ function GeoMap({
1034
1041
  const [dynamicPanelPosition, setDynamicPanelPosition] = React3__namespace.useState(
1035
1042
  panelPosition
1036
1043
  );
1044
+ const viewStateRef = React3__namespace.useRef(uncontrolledViewState);
1037
1045
  React3__namespace.useEffect(() => {
1038
1046
  if (!viewState && !defaultViewState) {
1039
- setUncontrolledViewState({
1040
- latitude: firstCoordinate.latitude,
1041
- longitude: firstCoordinate.longitude,
1042
- zoom: calculatedZoom
1047
+ setUncontrolledViewState((prev) => {
1048
+ if (prev.latitude === firstCoordinate.latitude && prev.longitude === firstCoordinate.longitude && prev.zoom === calculatedZoom) {
1049
+ return prev;
1050
+ }
1051
+ return {
1052
+ latitude: firstCoordinate.latitude,
1053
+ longitude: firstCoordinate.longitude,
1054
+ zoom: calculatedZoom
1055
+ };
1043
1056
  });
1044
1057
  }
1045
- }, [firstCoordinate, calculatedZoom, viewState, defaultViewState]);
1058
+ }, [
1059
+ // Use primitive values instead of objects to avoid reference changes
1060
+ firstCoordinate.latitude,
1061
+ firstCoordinate.longitude,
1062
+ calculatedZoom,
1063
+ viewState,
1064
+ defaultViewState
1065
+ ]);
1046
1066
  const isControlledViewState = viewState !== void 0;
1047
1067
  const resolvedViewState = isControlledViewState ? viewState : uncontrolledViewState;
1068
+ React3__namespace.useEffect(() => {
1069
+ viewStateRef.current = resolvedViewState || uncontrolledViewState;
1070
+ }, [
1071
+ // Use primitive values to avoid reference changes
1072
+ resolvedViewState?.latitude,
1073
+ resolvedViewState?.longitude,
1074
+ resolvedViewState?.zoom,
1075
+ uncontrolledViewState.latitude,
1076
+ uncontrolledViewState.longitude,
1077
+ uncontrolledViewState.zoom
1078
+ ]);
1048
1079
  const applyViewState = React3__namespace.useCallback(
1049
1080
  (nextState) => {
1050
1081
  if (!isControlledViewState) {
@@ -1083,7 +1114,13 @@ function GeoMap({
1083
1114
  setSelection({ type: "none" });
1084
1115
  onSelectionChange?.({ type: "none" });
1085
1116
  }
1086
- }, [onSelectionChange, selectedMarker, selection]);
1117
+ }, [
1118
+ // Use primitive values to avoid object reference issues
1119
+ selection.type,
1120
+ selection.markerId,
1121
+ selectedMarker?.id,
1122
+ onSelectionChange
1123
+ ]);
1087
1124
  const emitSelectionChange = React3__namespace.useCallback(
1088
1125
  (nextSelection) => {
1089
1126
  if (nextSelection.type === "none") {
@@ -1113,17 +1150,15 @@ function GeoMap({
1113
1150
  markerId: marker.id,
1114
1151
  clusterId: marker.clusterId
1115
1152
  });
1116
- const currentCenter = resolvedViewState || {
1117
- latitude: firstCoordinate.latitude,
1118
- longitude: firstCoordinate.longitude
1153
+ const currentState = viewStateRef.current;
1154
+ const center = {
1155
+ latitude: currentState.latitude ?? 0,
1156
+ longitude: currentState.longitude ?? 0
1119
1157
  };
1120
1158
  const optimalPosition = getOptimalPanelPosition(
1121
1159
  marker.latitude,
1122
1160
  marker.longitude,
1123
- {
1124
- latitude: currentCenter.latitude ?? firstCoordinate.latitude,
1125
- longitude: currentCenter.longitude ?? firstCoordinate.longitude
1126
- }
1161
+ center
1127
1162
  );
1128
1163
  setDynamicPanelPosition(optimalPosition);
1129
1164
  applyViewState({
@@ -1133,7 +1168,7 @@ function GeoMap({
1133
1168
  });
1134
1169
  emitSelectionChange({ type: "marker", marker });
1135
1170
  },
1136
- [applyViewState, emitSelectionChange, markerFocusZoom, resolvedViewState, firstCoordinate]
1171
+ [applyViewState, emitSelectionChange, markerFocusZoom]
1137
1172
  );
1138
1173
  const selectCluster = React3__namespace.useCallback(
1139
1174
  (cluster) => {
@@ -1141,17 +1176,15 @@ function GeoMap({
1141
1176
  type: "cluster",
1142
1177
  clusterId: cluster.id
1143
1178
  });
1144
- const currentCenter = resolvedViewState || {
1145
- latitude: firstCoordinate.latitude,
1146
- longitude: firstCoordinate.longitude
1179
+ const currentState = viewStateRef.current;
1180
+ const center = {
1181
+ latitude: currentState.latitude ?? 0,
1182
+ longitude: currentState.longitude ?? 0
1147
1183
  };
1148
1184
  const optimalPosition = getOptimalPanelPosition(
1149
1185
  cluster.latitude,
1150
1186
  cluster.longitude,
1151
- {
1152
- latitude: currentCenter.latitude ?? firstCoordinate.latitude,
1153
- longitude: currentCenter.longitude ?? firstCoordinate.longitude
1154
- }
1187
+ center
1155
1188
  );
1156
1189
  setDynamicPanelPosition(optimalPosition);
1157
1190
  applyViewState({
@@ -1161,7 +1194,7 @@ function GeoMap({
1161
1194
  });
1162
1195
  emitSelectionChange({ type: "cluster", cluster });
1163
1196
  },
1164
- [applyViewState, clusterFocusZoom, emitSelectionChange, resolvedViewState, firstCoordinate]
1197
+ [applyViewState, clusterFocusZoom, emitSelectionChange]
1165
1198
  );
1166
1199
  const clearSelection = React3__namespace.useCallback(() => {
1167
1200
  setSelection({ type: "none" });