Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

Prevent "Cannot read property 'layers' of undefined" error (#299) (#1910)

Igor Dykhta486e3239ae3f
diff --git a/src/reducers/vis-state-updaters.ts b/src/reducers/vis-state-updaters.ts
index a277f326f..59d629787 100644
--- a/src/reducers/vis-state-updaters.ts
+++ b/src/reducers/vis-state-updaters.ts
@@ -1878,12 +1878,12 @@ export function closeSpecificMapAtIndex<S extends VisState>(
): S {
// retrieve layers meta data from the remaining map that we need to keep
const indexToRetrieve = 1 - action.payload;
- const mapLayers = state.splitMaps[indexToRetrieve].layers;
+ const mapLayers = state.splitMaps[indexToRetrieve]?.layers;
const {layers} = state;
// update layer visibility
const newLayers = layers.map(layer =>
- !mapLayers[layer.id] && layer.config.isVisible
+ mapLayers && !mapLayers[layer.id] && layer.config.isVisible
? layer.updateLayerConfig({
// if layer.id is not in mapLayers, it should be inVisible
isVisible: false