From dee6ef54254238cc407b67707f1284b19f6267f8 Mon Sep 17 00:00:00 2001 From: "mbret@comand" Date: Tue, 17 Feb 2026 16:09:08 +0100 Subject: [PATCH] fix: prevent app wide crash when terrain properties are undefined --- modules/react-mapbox/src/components/source.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/react-mapbox/src/components/source.ts b/modules/react-mapbox/src/components/source.ts index 3139d61a7..4ecb3379a 100644 --- a/modules/react-mapbox/src/components/source.ts +++ b/modules/react-mapbox/src/components/source.ts @@ -108,7 +108,19 @@ export function Source(props: SourceProps) { } } } - map.removeSource(id); + + /** + * There is a bug in mapbox where style.terrain.properties may be undefined. + * @see https://github.com/mapbox/mapbox-gl-js/blob/7a72385de5c7400647ea7d3539637145fdf616a7/src/terrain/terrain.ts#L380 + * To prevent this component to crash, we catch it for now. + * This seems to be happening the majority of time with but not only. + */ + try { + map.removeSource(id); + } catch (error) { + // eslint-disable-next-line + console.error(error); + } } }; }