Skip to content

Commit 03c2aa2

Browse files
mrkevfacebook-github-bot
authored andcommitted
Don't SSR example editor on website. (#2356)
Summary: There's suspicion the example editor fails in prod because of an SSR error, so lets not SSR-it. Also upgrades draft to the latest version on npm. Pull Request resolved: facebookarchive/draft-js#2356 Test Plan: `yarn start`, played around with the editor. Reviewed By: claudiopro Differential Revision: D20532633 Pulled By: mrkev fbshipit-source-id: 934427d2e1a35232ee9f12632e539817a1f2eaa8
1 parent f5f1b2b commit 03c2aa2

File tree

3 files changed

+51
-1246
lines changed

3 files changed

+51
-1246
lines changed

website/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"@docusaurus/core": "^2.0.0-alpha.36",
1010
"@docusaurus/preset-classic": "^2.0.0-alpha.36",
1111
"classnames": "^2.2.6",
12-
"draft-js": "^0.11.3",
12+
"draft-js": "^0.11.4",
1313
"react": "^16.10.2",
1414
"react-dom": "^16.10.2"
1515
},

website/src/pages/index.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ import classnames from 'classnames';
1717
import DraftEditorExample from '../components/DraftEditorExample';
1818
import styles from './styles.module.css';
1919

20+
/** Won't render children on server */
21+
function ClientOnly({children, fallback}) {
22+
if (typeof window === 'undefined') {
23+
return fallback || null;
24+
}
25+
return children;
26+
}
27+
2028
function Home() {
2129
const context = useDocusaurusContext();
2230
const {siteConfig = {}} = context;
@@ -74,9 +82,9 @@ function Home() {
7482
target="_blank"
7583
rel="noreferrer noopener">
7684
immutable-js
77-
</a>, offering an API with functional state updates and
78-
aggressively leveraging data persistence for scalable memory
79-
usage.
85+
</a>
86+
, offering an API with functional state updates and aggressively
87+
leveraging data persistence for scalable memory usage.
8088
</p>
8189
</div>
8290
</div>
@@ -87,15 +95,17 @@ function Home() {
8795
'margin-vert--xl',
8896
styles.hideOnTabletAndSmaller,
8997
)}>
90-
<div className="col col--6 col--offset-3">
91-
<h2>Try it out!</h2>
92-
<p>
93-
Here's a simple example of a rich text editor built in Draft.js.
94-
</p>
95-
<div id="rich-example">
96-
<DraftEditorExample />
98+
<ClientOnly fallback={null}>
99+
<div className="col col--6 col--offset-3">
100+
<h2>Try it out!</h2>
101+
<p>
102+
Here's a simple example of a rich text editor built in Draft.js.
103+
</p>
104+
<div id="rich-example">
105+
<DraftEditorExample />
106+
</div>
97107
</div>
98-
</div>
108+
</ClientOnly>
99109
</div>
100110
<div className="margin-vert--xl text--center">
101111
<Link

0 commit comments

Comments
 (0)