Skip to content

Commit

Permalink
fix: Clear Event Listeners On Unmount (#851)
Browse files Browse the repository at this point in the history
  • Loading branch information
nayr974 authored Jan 6, 2025
1 parent 4445d65 commit 6ef5734
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ const LeafletMapWithServerSideClustering: React.FC<MapProps> = ({
),
);

// Fit the map to the bounds
mapRef?.current?.fitBounds(bounds, { padding: [35, 35] });
// Fit the map to the bounds. Disable animation due to known Leaflet issue if map unmounts while animating: https://github.com/Leaflet/Leaflet/issues/9527
mapRef?.current?.flyToBounds(bounds, { padding: [35, 35], animate: false });
} else if (defaultClusterView.center && defaultClusterView.zoom) {
mapRef?.current?.setView(defaultClusterView.center, defaultClusterView.zoom);
}
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/app/components/mapping/spiderfy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ const Spiderfy = (props: SpiderfyProps) => {
});
}, [oms, props]);

useEffect(() => {
return () => {
oms.clearListeners("spiderfy");
oms.clearListeners("unspiderfy");
oms.clearListeners("click");
};
}, [oms]);

useEffect(() => {
map.eachLayer((layer) => {
// Hacky, but "RiseOnHover" is being used to identify non-clustered markers that should be spiderfied.
Expand Down

0 comments on commit 6ef5734

Please sign in to comment.