@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.
@@ -1014,9 +1014,16 @@ function GeoMap({
1014
1014
  const updateDimensions = () => {
1015
1015
  if (containerRef.current) {
1016
1016
  const rect = containerRef.current.getBoundingClientRect();
1017
- setContainerDimensions({
1018
- width: rect.width || 800,
1019
- height: rect.height || calculatedHeight
1017
+ setContainerDimensions((prev) => {
1018
+ const newWidth = rect.width || 800;
1019
+ const newHeight = rect.height || calculatedHeight;
1020
+ if (prev.width === newWidth && prev.height === newHeight) {
1021
+ return prev;
1022
+ }
1023
+ return {
1024
+ width: newWidth,
1025
+ height: newHeight
1026
+ };
1020
1027
  });
1021
1028
  }
1022
1029
  };
@@ -1153,17 +1160,41 @@ function GeoMap({
1153
1160
  const [dynamicPanelPosition, setDynamicPanelPosition] = React3__namespace.useState(
1154
1161
  panelPosition
1155
1162
  );
1163
+ const viewStateRef = React3__namespace.useRef(uncontrolledViewState);
1156
1164
  React3__namespace.useEffect(() => {
1157
1165
  if (!viewState && !defaultViewState) {
1158
- setUncontrolledViewState({
1159
- latitude: firstCoordinate.latitude,
1160
- longitude: firstCoordinate.longitude,
1161
- zoom: calculatedZoom
1166
+ setUncontrolledViewState((prev) => {
1167
+ if (prev.latitude === firstCoordinate.latitude && prev.longitude === firstCoordinate.longitude && prev.zoom === calculatedZoom) {
1168
+ return prev;
1169
+ }
1170
+ return {
1171
+ latitude: firstCoordinate.latitude,
1172
+ longitude: firstCoordinate.longitude,
1173
+ zoom: calculatedZoom
1174
+ };
1162
1175
  });
1163
1176
  }
1164
- }, [firstCoordinate, calculatedZoom, viewState, defaultViewState]);
1177
+ }, [
1178
+ // Use primitive values instead of objects to avoid reference changes
1179
+ firstCoordinate.latitude,
1180
+ firstCoordinate.longitude,
1181
+ calculatedZoom,
1182
+ viewState,
1183
+ defaultViewState
1184
+ ]);
1165
1185
  const isControlledViewState = viewState !== void 0;
1166
1186
  const resolvedViewState = isControlledViewState ? viewState : uncontrolledViewState;
1187
+ React3__namespace.useEffect(() => {
1188
+ viewStateRef.current = resolvedViewState || uncontrolledViewState;
1189
+ }, [
1190
+ // Use primitive values to avoid reference changes
1191
+ resolvedViewState?.latitude,
1192
+ resolvedViewState?.longitude,
1193
+ resolvedViewState?.zoom,
1194
+ uncontrolledViewState.latitude,
1195
+ uncontrolledViewState.longitude,
1196
+ uncontrolledViewState.zoom
1197
+ ]);
1167
1198
  const applyViewState = React3__namespace.useCallback(
1168
1199
  (nextState) => {
1169
1200
  if (!isControlledViewState) {
@@ -1202,7 +1233,13 @@ function GeoMap({
1202
1233
  setSelection({ type: "none" });
1203
1234
  onSelectionChange?.({ type: "none" });
1204
1235
  }
1205
- }, [onSelectionChange, selectedMarker, selection]);
1236
+ }, [
1237
+ // Use primitive values to avoid object reference issues
1238
+ selection.type,
1239
+ selection.markerId,
1240
+ selectedMarker?.id,
1241
+ onSelectionChange
1242
+ ]);
1206
1243
  const emitSelectionChange = React3__namespace.useCallback(
1207
1244
  (nextSelection) => {
1208
1245
  if (nextSelection.type === "none") {
@@ -1232,17 +1269,15 @@ function GeoMap({
1232
1269
  markerId: marker.id,
1233
1270
  clusterId: marker.clusterId
1234
1271
  });
1235
- const currentCenter = resolvedViewState || {
1236
- latitude: firstCoordinate.latitude,
1237
- longitude: firstCoordinate.longitude
1272
+ const currentState = viewStateRef.current;
1273
+ const center = {
1274
+ latitude: currentState.latitude ?? 0,
1275
+ longitude: currentState.longitude ?? 0
1238
1276
  };
1239
1277
  const optimalPosition = getOptimalPanelPosition(
1240
1278
  marker.latitude,
1241
1279
  marker.longitude,
1242
- {
1243
- latitude: currentCenter.latitude ?? firstCoordinate.latitude,
1244
- longitude: currentCenter.longitude ?? firstCoordinate.longitude
1245
- }
1280
+ center
1246
1281
  );
1247
1282
  setDynamicPanelPosition(optimalPosition);
1248
1283
  applyViewState({
@@ -1252,7 +1287,7 @@ function GeoMap({
1252
1287
  });
1253
1288
  emitSelectionChange({ type: "marker", marker });
1254
1289
  },
1255
- [applyViewState, emitSelectionChange, markerFocusZoom, resolvedViewState, firstCoordinate]
1290
+ [applyViewState, emitSelectionChange, markerFocusZoom]
1256
1291
  );
1257
1292
  const selectCluster = React3__namespace.useCallback(
1258
1293
  (cluster) => {
@@ -1260,17 +1295,15 @@ function GeoMap({
1260
1295
  type: "cluster",
1261
1296
  clusterId: cluster.id
1262
1297
  });
1263
- const currentCenter = resolvedViewState || {
1264
- latitude: firstCoordinate.latitude,
1265
- longitude: firstCoordinate.longitude
1298
+ const currentState = viewStateRef.current;
1299
+ const center = {
1300
+ latitude: currentState.latitude ?? 0,
1301
+ longitude: currentState.longitude ?? 0
1266
1302
  };
1267
1303
  const optimalPosition = getOptimalPanelPosition(
1268
1304
  cluster.latitude,
1269
1305
  cluster.longitude,
1270
- {
1271
- latitude: currentCenter.latitude ?? firstCoordinate.latitude,
1272
- longitude: currentCenter.longitude ?? firstCoordinate.longitude
1273
- }
1306
+ center
1274
1307
  );
1275
1308
  setDynamicPanelPosition(optimalPosition);
1276
1309
  applyViewState({
@@ -1280,7 +1313,7 @@ function GeoMap({
1280
1313
  });
1281
1314
  emitSelectionChange({ type: "cluster", cluster });
1282
1315
  },
1283
- [applyViewState, clusterFocusZoom, emitSelectionChange, resolvedViewState, firstCoordinate]
1316
+ [applyViewState, clusterFocusZoom, emitSelectionChange]
1284
1317
  );
1285
1318
  const clearSelection = React3__namespace.useCallback(() => {
1286
1319
  setSelection({ type: "none" });