Skip to content

Commit

Permalink
Allow to disable SSR with REACT_XMASONRY_SSR_ENABLED=false
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitaeverywhere committed Jan 26, 2021
1 parent 8ad1431 commit d2cf3d7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-xmasonry",
"version": "3.0.4",
"version": "3.0.5",
"description": "Simple & featured native masonry layout implementation for React JS",
"main": "dist/index.js",
"types": "types.d.ts",
Expand Down
8 changes: 7 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Warning: do not stick XBlock's content styling to `.xblock` selector. Use `.xmas
how [XMasonry works](#xmasonry-under-the-hood) to understand why: the `.xblock` class is applied
only **after** the content measurements are done.

### Server Rendering Note
### Server-Side Rendering

XMasonry, being rendered on the server ([renderToStaticMarkup](https://facebook.github.io/react/docs/react-dom-server)),
will be unable to detect content heights due server rendering algorithm limitations.
Expand All @@ -157,6 +157,12 @@ server-rendered result look more consistent with the client's one, for example:
}
```

You can disable SSR by using the following environment variable passed to your renderer:

```bash
REACT_XMASONRY_SSR_ENABLED=false
```

Configuring Components
----------------------

Expand Down
3 changes: 2 additions & 1 deletion src/utils/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export const debounce = (f, rate = 45) => {
}
};

export const isServer = !(typeof document !== "undefined" && typeof window !== "undefined");
export const isServer = ((process || {}).env || {}).REACT_XMASONRY_SSR_ENABLED !== 'false'
&& !(typeof document !== "undefined" && typeof window !== "undefined");

0 comments on commit d2cf3d7

Please sign in to comment.