Skip to content

Commit 8741b25

Browse files
adrianlztJulian Dehm
authored andcommitted
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'.
1 parent 053999d commit 8741b25

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/MarkerClusterGroup.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ export var MarkerClusterGroup = L.MarkerClusterGroup = L.FeatureGroup.extend({
125125
currentZoom = this._zoom;
126126
if (layer.__parent) {
127127
while (visibleLayer.__parent._zoom >= currentZoom) {
128+
// Check if visibleLayer.__parent is undefined to avoid crashing in the next loop.
129+
if (visibleLayer.__parent === undefined) {
130+
break;
131+
}
128132
visibleLayer = visibleLayer.__parent;
129133
}
130134
}
@@ -730,7 +734,7 @@ export var MarkerClusterGroup = L.MarkerClusterGroup = L.FeatureGroup.extend({
730734
delete e.target.__dragStart;
731735
if (dragStart) {
732736
this._moveChild(e.target, dragStart, e.target._latlng);
733-
}
737+
}
734738
},
735739

736740

0 commit comments

Comments
 (0)