Hashnode / Hashnode/mern-starter

Disable server side rendering for a given route

Open
#252 1 comment 3 reactions 0 assignees View on GitHub
V2.9.0
Dominant language
JavaScript
Stars
5.1k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

Hi,

I try to set up a new react-leaflet component. When I try to access my route, I get an error :

> ReferenceError: window is not defined
> at Object. (.../leaflet/dist/leaflet-src.js:13043:3)

This error is totally fine because Leaflet needs access to the DOM to render properly.

> Leaflet makes direct calls to the DOM when it is loaded, therefore this library is not compatible with server-side rendering. ([here](https://github.com/snario/react-mapbox-gl/blob/master/README.md#technical-considerations))

Is it possible to disable server side rendering for a given route ? What are the best practice to do so ?

Thank you :)

EDIT: I check before using my component if I'm on the browser or not. It works but I guess It's not a really nice way to do this... Any clues ?

```
if(process.title === 'browser'){
//render my component
}else {
return null
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.