[Bug] Error: Source "mapbox-dem" cannot be removed while terrain is using it.
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- react, typescript
- Domain
- frontend
Research direction
Start by tracing how Map handles reuseMaps unmounting and how the nested Source is removed when terrain references it. Reproduce the example with reuseMaps, terrain, and the mapbox-dem Source, then compare the existing cleanup behavior with the reported MapCleanup workaround. Done means navigating away no longer raises the source-removal error.
Written by the indexing model from the issue text.
Description
Description
This is the code from your example:
return (
<>
<Map
initialViewState={{
latitude: 32.6141,
longitude: -114.34411,
zoom: 14,
bearing: 80,
pitch: 80,
}}
maxPitch={85}
mapStyle="mapbox://styles/mapbox/satellite-v9"
mapboxAccessToken={env.NEXT_PUBLIC_MAPBOX_ACCESS_TOKEN}
terrain={{ source: "mapbox-dem", exaggeration: 1.5 }}
>
<Source
id="mapbox-dem"
type="raster-dem"
url="mapbox://mapbox.mapbox-terrain-dem-v1"
tileSize={512}
maxzoom={14}
/>
</Map>
</>
);
When you add reuseMaps to the Map component, and you navigate to another page (so you unmount Map)
You have this error:
Error: Source "mapbox-dem" cannot be removed while terrain is using it.
I can fix is creating a cleanup composant like :
function MapCleanup() {
const { current: map } = useMap();
React.useEffect(() => {
return () => {
if (map) {
try {
map.getMap().setTerrain(undefined);
} catch (error) {
console.warn("Error:", error);
}
}
};
}, [map]);
return null;
}
And use it like:
return (
<>
<Map
reuseMaps
initialViewState={{
latitude: 32.6141,
longitude: -114.34411,
zoom: 14,
bearing: 80,
pitch: 80,
}}
maxPitch={85}
mapStyle="mapbox://styles/mapbox/satellite-v9"
mapboxAccessToken={env.NEXT_PUBLIC_MAPBOX_ACCESS_TOKEN}
terrain={{ source: "mapbox-dem", exaggeration: 1.5 }}
>
<MapCleanup />
<Source
id="mapbox-dem"
type="raster-dem"
url="mapbox://mapbox.mapbox-terrain-dem-v1"
tileSize={512}
maxzoom={14}
/>
</Map>
</>
);
But its a lot of lines... Would it be possible to add map.getMap().setTerrain(undefined); when reuseMaps unmount mapbox-dem source ?
Expected Behavior
No response
Steps to Reproduce
See my message up
Environment
- Framework version: "react-map-gl": "^8.0.4",
- Map library: "mapbox-gl": "^3.14.0",
- Browser: Chrome 139.0.7258.138
- OS: Ubuntu
Logs
No response
- Dominant language
- TypeScript
- Stars
- 8.5k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from visgl/react-map-gl
-
DEFAULT_SETTINGS.maxBounds in @vis.gl/react-maplibre has 360° longitude span, triggers maplibre-gl-js#6148 crash via _updateSettings fallbackMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
visgl/react-map-gl#2591 · 2 comments ·
-
[Bug] Mapbox geocoder example crashes: "i is not a function"Possibly taken @yuiseki claimed this 20 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
visgl/react-map-gl#2628 ·
-
[Bug] Scroll zoom stops short of maxZoom in controlled mode with MapLibrePossibly taken @sviat-barbutsa claimed this 33 days ago. Openbug
Difficulty 3/5 Half a day Newbie friendliness 74/100
visgl/react-map-gl#2626 ·
-
[Bug] reuseMaps: Mapbox.reuse() infinite-loops (tab freeze) when the recycled map's container is the mount containerPossibly taken @mikeyfarina claimed this 82 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 68/100
visgl/react-map-gl#2613 ·
-
feature
Difficulty 5/5 Over a week Newbie friendliness 42/100
visgl/react-map-gl#2603 · 1 reaction ·
All issues in visgl/react-map-gl
Similar issues
-
accessibility area:ci ci-test level:low priority:high type:test
Difficulty 2/5 1-3 hours Newbie friendliness 71/100
skytuhua-org/Gen-V1#3132 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
drmrd/vernacular#1238 ·
Maintainers usually reply within 1 day
-
question
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
enhancement migration-prioritized
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Hudson-Pufferfish/local-party-console#136 ·
Maintainers usually reply within 1 day
-
priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day