Skip to content

Commit

Permalink
🐛 [open-formulieren/open-forms#5038] Missing map shapes in summary
Browse files Browse the repository at this point in the history
Because the geoJsonGeometry is available before the featureGroupRef is set, can the useEffect hook not draw the map shapes
  • Loading branch information
robinmolen committed Jan 30, 2025
1 parent 775bb98 commit 8408f1e
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/components/Map/LeafletMap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,27 @@ const LeaftletMap = ({
onGeoJsonGeometrySet?.(newFeatureLayer.toGeoJSON().geometry);
};

useEffect(() => {
// Remove all shapes from the map.
// Only `geoJsonGeometry` should be shown on the map.
featureGroupRef.current?.clearLayers();
if (!geoJsonGeometry) {
return;
}
// Add the current `geoJsonGeometry` as shape
const layer = Leaflet.GeoJSON.geometryToLayer(geoJsonGeometry);
featureGroupRef.current?.addLayer(layer);
}, [geoJsonGeometry]);
useEffect(
() => {
if (!featureGroupRef.current) {
// If there is no feature group, nothing should be done..
return;
}

// Remove all shapes from the map.
// Only `geoJsonGeometry` should be shown on the map.
featureGroupRef.current.clearLayers();
if (!geoJsonGeometry) {
return;

Check warning on line 106 in src/components/Map/LeafletMap.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Map/LeafletMap.jsx#L106

Added line #L106 was not covered by tests
}
// Add the current `geoJsonGeometry` as shape
const layer = Leaflet.GeoJSON.geometryToLayer(geoJsonGeometry);
featureGroupRef.current.addLayer(layer);
},
// `featureGroupRef.current` is needed as dependency to make sure that
// the featureGroupRef can be used.
[geoJsonGeometry, featureGroupRef.current]

Check warning on line 114 in src/components/Map/LeafletMap.jsx

View workflow job for this annotation

GitHub Actions / Create storybook build

React Hook useEffect has an unnecessary dependency: 'featureGroupRef.current'. Either exclude it or remove the dependency array. Mutable values like 'featureGroupRef.current' aren't valid dependencies because mutating them doesn't re-render the component

Check warning on line 114 in src/components/Map/LeafletMap.jsx

View workflow job for this annotation

GitHub Actions / Create 'production' build

React Hook useEffect has an unnecessary dependency: 'featureGroupRef.current'. Either exclude it or remove the dependency array. Mutable values like 'featureGroupRef.current' aren't valid dependencies because mutating them doesn't re-render the component

Check warning on line 114 in src/components/Map/LeafletMap.jsx

View workflow job for this annotation

GitHub Actions / Create 'production' build

React Hook useEffect has an unnecessary dependency: 'featureGroupRef.current'. Either exclude it or remove the dependency array. Mutable values like 'featureGroupRef.current' aren't valid dependencies because mutating them doesn't re-render the component

Check warning on line 114 in src/components/Map/LeafletMap.jsx

View workflow job for this annotation

GitHub Actions / Create 'production' build

React Hook useEffect has an unnecessary dependency: 'featureGroupRef.current'. Either exclude it or remove the dependency array. Mutable values like 'featureGroupRef.current' aren't valid dependencies because mutating them doesn't re-render the component

Check warning on line 114 in src/components/Map/LeafletMap.jsx

View workflow job for this annotation

GitHub Actions / Lint code (ESLint)

React Hook useEffect has an unnecessary dependency: 'featureGroupRef.current'. Either exclude it or remove the dependency array. Mutable values like 'featureGroupRef.current' aren't valid dependencies because mutating them doesn't re-render the component
);

return (
<>
Expand Down

0 comments on commit 8408f1e

Please sign in to comment.