From e4b93e4caac88708d6e07d8f9a39a14fe37eec62 Mon Sep 17 00:00:00 2001 From: Adrian Lopez Date: Wed, 2 Feb 2022 14:19:48 +0100 Subject: [PATCH] Avoid crashing with some zoom events In certains ocasions we see a crash in the app while changing zoom. The error is: Cannot read properties of undefined (reading '_zoom') The problem comes from that while, iterating through the visibleLayer parents until it hits one undefined and then crashed trying to read '_zoom'. --- src/MarkerClusterGroup.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js index 38c15920..ff56c133 100644 --- a/src/MarkerClusterGroup.js +++ b/src/MarkerClusterGroup.js @@ -125,6 +125,10 @@ export var MarkerClusterGroup = L.MarkerClusterGroup = L.FeatureGroup.extend({ currentZoom = this._zoom; if (layer.__parent) { while (visibleLayer.__parent._zoom >= currentZoom) { + // Check if visibleLayer.__parent is undefined to avoid crashing in the next loop. + if (visibleLayer.__parent === undefined) { + break; + } visibleLayer = visibleLayer.__parent; } } @@ -726,7 +730,7 @@ export var MarkerClusterGroup = L.MarkerClusterGroup = L.FeatureGroup.extend({ delete e.target.__dragStart; if (dragStart) { this._moveChild(e.target, dragStart, e.target._latlng); - } + } },