Skip to content

Commit 7b62866

Browse files
committed
fix: wrap MapViewUpdater operations in try/catch to prevent unmount errors
1 parent 702a4bb commit 7b62866

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

frontend/src/components/ChapterMap.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const MapViewUpdater = ({
7474

7575
useEffect(() => {
7676
if (!map) return
77+
try{
7778
const container = map.getContainer()
7879
if (!container) return
7980
const width = container.clientWidth
@@ -122,10 +123,14 @@ const MapViewUpdater = ({
122123
map.fitBounds(localBounds, { maxZoom: maxZoom, padding: [padding, padding] })
123124
} else {
124125
map.setView([20, 0], Math.max(dynamicMinZoom, 2))
125-
}
126-
}, [userLocation, showLocal, validGeoLocData, map])
126+
}
127+
} catch {
128+
// the map container was removed before update complite
127129

128-
return null
130+
}
131+
[userLocation, showLocal, validGeoLocData, map])
132+
133+
return null
129134
}
130135

131136
const ChapterMap = ({

0 commit comments

Comments
 (0)