I currently play around with the new nextjs13 and the app directory as well as server side only code. In my project i use React leaflet and this cannot be directly used anymore in Nextjs13 (with the app directory). It is required to load the client components differently or via dynamic. In my project i use the 2nd option via dynamic and created a File for the components that can be lazy loaded:
Unfortunately, this is not working (Error: Error: Bounds are not valid. - Thrown in that Line). After some debugging i assume that this is reladed to the dynamic loading of Markers. In the code lines above, you can see that i log some lines after the Map is loaded. The Layers the Map is empty but in the console.log it's possible to see that there is an array with layers that contains the Marker.
Thanks a lot
P.s.: I know that I can change the way and pass the marker data via Json down to the MapComponent without a use of dynamic. But I really would like to use it in the way where everything is prepared in the page.tsxfile - so on the server side.
Expected behavior
The map should set the boundaries where all marker fit.
Bug report in v4
I currently play around with the new nextjs13 and the app directory as well as server side only code. In my project i use React leaflet and this cannot be directly used anymore in Nextjs13 (with the app directory). It is required to load the client components differently or via
dynamic
. In my project i use the 2nd option viadynamic
and created a File for the components that can be lazy loaded:These dynamic components are loaded in the
app/page.tsx
fileWhen I run this project, it works like expected and i can see a map with the configured markers.
Actual behavior
I would like to set the Zoom the map in that way, that all Markers are visible. Leaflet offer a possibility for that use-case by using
getBounds
.Unfortunately, this is not working (Error:
Error: Bounds are not valid.
- Thrown in that Line). After some debugging i assume that this is reladed to the dynamic loading of Markers. In the code lines above, you can see that i log some lines after the Map is loaded. The Layers the Map is empty but in the console.log it's possible to see that there is an array with layers that contains the Marker.Thanks a lot
P.s.: I know that I can change the way and pass the marker data via Json down to the MapComponent without a use of dynamic. But I really would like to use it in the way where everything is prepared in the
page.tsx
file - so on the server side.Expected behavior
The map should set the boundaries where all marker fit.
Steps to reproduce
Since this is a more complex problem, I created a github repo where the issue is visible. https://github.com/a-marcel/nextjs13-app-dynamic-loaded-marker/tree/main