From 29f995d8855611cc1acc1e8218448a335c52045a Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 29 Apr 2026 23:07:41 +0000 Subject: [PATCH] fix(map): boundary lifecycle cleanup on place deselection Clear boundary source data when: - Clicking outside the marker circle (deselecting) - Clicking a new place (before setting new boundary) - Clicking empty map area (generic map click) This ensures: 1. Re-clicking the same city after dismissing re-renders boundary (selectedPlace is properly cleared, triggering fresh useEffect) 2. Clicking away doesn't leave stale boundary outline (boundary source explicitly cleared to empty FeatureCollection) Co-Authored-By: Claude Opus 4.5 --- src/components/MapView.jsx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/components/MapView.jsx b/src/components/MapView.jsx index b09f0f2..a79c545 100644 --- a/src/components/MapView.jsx +++ b/src/components/MapView.jsx @@ -1252,6 +1252,12 @@ const MapView = forwardRef(function MapView(_, ref) { // Outside circle → deselect, no new selection store.clearClickMarker() store.clearSelectedPlace() + // Clear boundary when deselecting + const boundarySource = map.getSource(BOUNDARY_SOURCE) + if (boundarySource) { + boundarySource.setData({ type: 'FeatureCollection', features: [] }) + } + setSelectedHighlight(map, null) } } else { // State A: nothing selected → select @@ -1267,7 +1273,7 @@ const MapView = forwardRef(function MapView(_, ref) { // Find first feature with a name (respects layer order = priority) const labelFeature = features.find(f => f.properties?.name) - // Clear previous feature highlight + // Clear previous feature highlight and boundary if (highlightedFeatureRef.current) { const { source, sourceLayer, id } = highlightedFeatureRef.current try { @@ -1276,6 +1282,11 @@ const MapView = forwardRef(function MapView(_, ref) { highlightedFeatureRef.current = null } setSelectedHighlight(map, null) + // Clear old boundary before setting new place + const boundarySource = map.getSource(BOUNDARY_SOURCE) + if (boundarySource) { + boundarySource.setData({ type: 'FeatureCollection', features: [] }) + } if (labelFeature) { // Clicked a labeled feature — snap to geometry and highlight @@ -1330,6 +1341,11 @@ const MapView = forwardRef(function MapView(_, ref) { }) } else { // No labeled feature — show reticle at click point + // Clear any existing boundary when clicking empty map + const boundarySource = map.getSource(BOUNDARY_SOURCE) + if (boundarySource) { + boundarySource.setData({ type: 'FeatureCollection', features: [] }) + } store.setClickMarker({ lat, lon: lng,