Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue with Map Container is already initialized #1073

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mistenkt
Copy link

@mistenkt mistenkt commented Apr 19, 2023

Was running into this error quite frequently when using this library on a Next project where our maps were being loaded using next/dynamic to prevent SSR.

Previous suggestions about adding keys to the MapContainer component were not working.

Noticed that the code for checking if we have an existin context is not actually updated if/when the context changes, and instead explicitly ignoring the lint warnings for this. // eslint-disable-next-line react-hooks/exhaustive-deps.

This fixes the problem.

Related issue: #1069

@yuzhakovvv
Copy link

Any updates here? 👀

@natBizitza
Copy link

Hi, any update on this PR?😎

@mistenkt
Copy link
Author

mistenkt commented Jul 5, 2023

Until this is merged and a new release is created, you can use my branch by adding the following in your package.json

"react-leaflet": "https://github.com/mistenkt/react-leaflet/archive/refs/tags/react-leaflet-v4.2.1-gitpkg.tar.gz",

we've been using it in prod for a few months now without any issues.

@natBizitza
Copy link

Until this is merged and a new release is created, you can use my branch by adding the following in your package.json

"react-leaflet": "https://github.com/mistenkt/react-leaflet/archive/refs/tags/react-leaflet-v4.2.1-gitpkg.tar.gz",

we've been using it in prod for a few months now without any issues.

Thank you! It works very well for me!

@lemilonkh
Copy link

We are also facing this issue, which is breaking hot reloads on our pages that have maps on them.
@PaulLeCam can this PR be merged and a new release be created? Thanks!

@tswacast
Copy link

This fixed the issue for us as well. If we can do anything to help get this PR merged into the new release, let us know. Much appreciated.

@stephanmantler
Copy link

This change didn't fix the issue for me, but another small tweak did. Although I am pretty sure it is a crude symptomatic solution and not a proper fix, thus no PR. But I basically just ensured _leaflet_id was undefined before calling the constructor:

// MapContainer.js 
28   const mapRef = useCallback((node)=>{
29      if (node !== null && context === null) {
30           // --- ensure LeafletMap does not get confused by id set in a previous render
31           node._leaflet_id = null;
32           const map = new LeafletMap(node, options);

(Next.js 15.0.2, React 18.3.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants