react-leaflet icon indicating copy to clipboard operation
react-leaflet copied to clipboard

"Map container is being reused by another instance" when using the new React Activity component

Open tomerzcod7 opened this issue 3 months ago • 7 comments

Expected behavior

React new Activity component should be perfect to offload the map for lower priority rendering and preserving state. However it seems like the MapContainer implementation does not support it properly

https://react.dev/reference/react/Activity

Actual behavior

You get the following error in the console: "Map container is being reused by another instance"

Steps to reproduce

Using the Activity component and toggle between hiding and viewing the map container:

<Activity mode={activeTab === 'map' ? 'visible' : 'hidden'}>
  <MapContainer center={center} zoom={zoom}>
    <TileLayer url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" />
  </MapContainer>
</Activity>

tomerzcod7 avatar Oct 09 '25 12:10 tomerzcod7

same error

Pedro-phd avatar Oct 17 '25 21:10 Pedro-phd

same here

gabrielbryk avatar Oct 27 '25 20:10 gabrielbryk

+1

AlejandroRM-DEV avatar Nov 04 '25 18:11 AlejandroRM-DEV

Same here, did someone found a workaround for this?

vanwalj avatar Nov 15 '25 15:11 vanwalj

+1

mariio46 avatar Nov 25 '25 08:11 mariio46

same problem

kaeon avatar Nov 25 '25 08:11 kaeon

From the documentation: https://react-leaflet.js.org/docs/start-introduction/#limitations

React's Activity component executes effects while retaining the map container element, making it incompatible with how React Leaflet works. A unique key property can be set on a MapContainer element to reset it.

maxmarchuk avatar Nov 25 '25 18:11 maxmarchuk