From 5052dfbf3735ff07319b7bd7108ae9448b0c2840 Mon Sep 17 00:00:00 2001 From: Mauricio Robayo Date: Mon, 1 Apr 2024 15:13:52 -0500 Subject: [PATCH] fix: map controls crashing when invalid key is provided (#290) --- src/components/map-control.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/map-control.tsx b/src/components/map-control.tsx index 105aee7..3a20f76 100644 --- a/src/components/map-control.tsx +++ b/src/components/map-control.tsx @@ -58,7 +58,11 @@ export const MapControl = ({children, position}: MapControlProps) => { controls.push(controlContainer); return () => { - const index = controls.getArray().indexOf(controlContainer); + const controlsArray = controls.getArray(); + // controlsArray could be undefined if the map is in an undefined state (e.g. invalid API-key, see #276 + if (!controlsArray) return; + + const index = controlsArray.indexOf(controlContainer); controls.removeAt(index); }; }, [controlContainer, map, position]);