Closed AndresMpa closed 9 months ago
Hey, You might want to add "use client" on the map component (a.k.a make it client component) based on the docs on introduction section, react leaflet is incompatible with SSR
Leaflet makes direct calls to the DOM when it is loaded,
therefore React Leaflet is not compatible with server-side rendering.
Hey, You might want to add "use client" on the map component (a.k.a make it client component) based on the docs on introduction section, react leaflet is incompatible with SSR
Leaflet makes direct calls to the DOM when it is loaded, therefore React Leaflet is not compatible with server-side rendering.
That solved its first render. now there's an error on what it renders. I want to achieve something like this: https://next-leaflet-starter.netlify.app/
But what I'm getting is just a set of chunks or pieces of a map
I'm actually rendering it using this:
const Map = useMemo(() => dynamic(
() => import('@/components/map/simple-map'),
{
loading: () => <p>A map is loading</p>,
ssr: false
}
), [])
return (
<>
<h2>My map</h2>
<div className="bg-orange-700 mx-auto w-11/12 h-[480px]">
<Map />
</div>
</>
)
Looks like you forgot the CSS!
import "leaflet/dist/leaflet.css";
import "leaflet-defaulticon-compatibility/dist/leaflet-defaulticon-compatibility.css";
import "leaflet-defaulticon-compatibility";
import {MapContainer, Marker, TileLayer} from "react-leaflet";
// etc.
I'm not sure if using https://www.npmjs.com/package/leaflet-defaulticon-compatibility is required. Your results may vary.
worked for me.
I finally got a working component, actually half of the blame was due to what @theNailz said. I decided to wrote a medium article explaining my mistakes, so I will leave it here:
It must be enough for the specific version I mentioned in the title of this issue
Thanks guys, you rock it 👍🏼
This was very helpful, specially because the autocomplete doesn't show the CSS file for some reason.
What I'm doing
I just copy pasted the example from react-leaflet
export default function Main() { return ( <> <MapContainer center={[40.8054, -74.0241]} zoom={14} scrollWheelZoom={false} style={{ height: "100%", width: "100%" }}
Expected behaviour
Redender a map on Nextjs v14 from a default template project
Current behaviour
Fatal error:
Dependencies
My desire
Not to downgrade Netxjs version