-
Notifications
You must be signed in to change notification settings - Fork 890
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Support server-side rendering #45
Comments
The issue is with Leaflet itself, as it doesn't check if the DOM is available when it's loaded, not directly this library. The solution you presented may work for you, but it's completely dependant on your environment and your build, it would probably not work in other cases. |
@PaulLeCam We could provide a React Component as fallback for server side rendering, check if
|
@iam4x Feel free to implement any workaround in your app... As I previously explained, this issue is not caused by this lib. |
Thanks for the workarounds gents, I ended up just using a client side bower package and not the react package, but will switch back now I know the render could be defined conditionally based on the environment |
@dougajmcdonald similar idea I'm using too. It's more flexible and maintainable. |
@dougajmcdonald I was wondering what was the solution for this? You guys are loading leaflet in with bower, and then proceeding to require |
May someone give the example of this workaround |
It's ugly, but it works.
|
For future googlers, there is also https://github.com/masotime/react-leaflet-universal And some attempts to render leaflet on the server: |
it works, too. In index.html: Include ..rel="stylesheet" href="https://unpkg.com/leaflet@1.2.0/dist/leaflet.css".. In React Component `import React, { Component } from 'react' class Mapa extends Component {
} export default Mapa` |
The cleanest solution i found is here : https://github.com/etalab/adresse.data.gouv.fr/blob/0bc6dd7/pages/map.js#L5-L12 |
rktel how to extends MapControl with componentWillMount(). |
For anyone wondering I managed to get this working using react-loadable for now In your parent component do something like so: Then I made a component called SearchResultMap.tsx and inside is: `import * as React from 'react'; export default class SearchResultMap extends React.Component {
}` |
Sorry, but how i pass props with this dynamic |
Hopefully this will help someone...If you're using gatsby then for some reason using the react-leaflet gatsby plugin works rather than using the library straight...weird but it saved me a lot of headache. |
This might be helpful for those who use Webpack & es6 dynamic import feature:
|
This worked for me in React 18. MyMap is the component that has the leaflet imports. Then you can use Suspense if you want to render something else while it is importing.
|
https://github.com/PaulLeCam/react-leaflet#technical-considerations have the following point:
I would like to discuss of the possibilities how it's possible to add server-side support for this library.
My current solution just skip rendering the leaflet on server-side, and render just on client-side:
I don't believe it's a best practice, but still it's something, than nothing, and I think it's better than using the
headless-leaflet
fork.The text was updated successfully, but these errors were encountered: