Skip to content

Commit

Permalink
Avoid crashing with some zoom events
Browse files Browse the repository at this point in the history
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'.
  • Loading branch information
adrianlzt committed Feb 2, 2022
1 parent 31360f2 commit e4b93e4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/MarkerClusterGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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);
}
}
},


Expand Down

0 comments on commit e4b93e4

Please sign in to comment.