PaulLeCam / react-leaflet

React components for Leaflet maps
https://react-leaflet.js.org
Other
5.16k stars 886 forks source link

Cannot read properties of undefined (reading '_leaflet_pos') #1136

Closed iqbalhassan-7654 closed 1 month ago

iqbalhassan-7654 commented 5 months ago

Bug report in v4

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.

Expected behavior

Please describe.

Actual behavior

Please describe.

Steps to reproduce

Please provide the simplest example possible to reproduce the issue, based on this StackBlitz.

iqbalhassan-7654 commented 5 months ago

image

piotr-cz commented 4 months ago

I think this may happen when you access native leaflet methods at the time when map container is unmounted.

For example I'm attempting to store map bounds in a state when user navigates to another page. At the same time I'm unmounting map container

marcoangelo commented 2 months ago

@piotr-cz How are you unmounting the map container? I am getting a similar issue as in this bug report; I try to use the remove() method on the map instance (when using the useMap hook) in a hook cleanup effect, but get a [Map container is already initialized] error.

piotr-cz commented 2 months ago

@marcoangelo Now I'm using external state, so it's updates don't trigger leaflet methods after component has been unmounted