When popup touches border of map whole app dies in callback hell
Bug report
Before opening an issue, make sure to read the contributing guide and understand this is a bug tracker, not a support platform.
Please make sure to check the following boxes before submitting an issue.
Issues opened without using this template will be closed unless they have a good reason not to follow this template.
- [x] All peer dependencies are installed: React, ReactDOM and Leaflet.
- [x] Using a supported version of React and ReactDOM (v17.0.0 minimum).
- [x] Using the supported version of Leaflet (v1.7.1 minimum) and its corresponding CSS file is loaded.
- [x] Using the latest v3 version of React-Leaflet.
- [x] The issue has not already been reported.
- [x] Make sure you have followed the quick start guide for Leaflet.
- [x] Make sure you have fully read the documentation and that you understand the limitations.
Expected behavior
'zoom' and 'center' properties for MapContainer are used during map creation so changing them after map was created should not impact map/popups behavior?
Actual behavior
Okay this will be tough... I tried reproducing it on codepen, but in would require me to rewrite half of the project there so I will just try to explain what I am trying to do. I want to have few external buttons to change between maps. Change tilemaps, change markers etc. but I also want to keep information like zoom and current map position when user would return to one map he has visited. For that I wrote this fragment to store data in React Store:
export const UpdateMapZoomAndPositionInStore = () => {
const map = useMap();
const {regionId} = GetMapPathParams();
const dispatch = useDispatch();
const onChange = useCallback(() => {
if (!parseInt(regionId)) return;
dispatch(UpdateRegionZoomPositionState(parseInt(regionId), map.getZoom(), map.getCenter()))
}, [map])
const handlers = useMemo(() => ({move: onChange, zoom: onChange}), [])
useMapEvents(handlers)
return null;
}
Then when I have Map container I set the zoom using values from store if they exist
center: regionState?.center || new LatLng(region.centerPosY, region.centerPosX),
defaultZoom: regionState?.zoom || region.defaultZoom,
And this works. I can change maps, I see changes in position and zoom are loaded properly but the problem starts when I open the popup. I can move around the map as long as I want until popup hits the border of the map. Then whole app dies in somekind of callback hell.

From what I was able to test locally there is some kind of problem with useCallback. The moment I stop using this UpdateMapZoomAndPositionInStore hook it works normally, I can scroll around the map with popup open.
Steps to reproduce
Sorry but I have problems reproducing it in a small snippet of code. Only thing I can propose is recording a video or geting in touch on meeting to present the behaviour and whole code snippets.
Please provide a simple way to reproduce the issue using the provided CodePen, if you can't it's most likely your issue comes from your own logic.
I've had this issue too. I found it was when the popup was auto panning the map. If you can afford to set auto pan to false, it will prevent this from happening. It's a bandaid to the problem, but it prevents crashes
@PaulLeCam "One is accident, two is coincidence, three is a pattern". I found behaviour that to me looks like a bug so I reported it and I want to help as much as I can, but I could not reproduce it on codepen. My offer for a remote call to show some code and do some debugging still stands, but also since Chris found that it may be related to auto pan I will try to find a cause on my own. Now since I can't provide a code snippet you can just close the issue/we can try to find a cause and solve it or you can just leave it open if I find something I will share my findings here.
If you can't provide a simple example to reproduce the issue, it's most likely coming from your own logic. I don't do individual support so I'll close this issue but please feel free to reopen if you can reproduce it in the provided codepen.