Skip to content

Commit aa41313

Browse files
committed
Make CodeMirror load dynamically to avoid document undefined error
1 parent 1334429 commit aa41313

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

components/Carbon.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import hljs from 'highlight.js/lib/core'
55
import javascript from 'highlight.js/lib/languages/javascript'
66
import debounce from 'lodash.debounce'
77
import ms from 'ms'
8-
import { Controlled as CodeMirror } from 'react-codemirror2'
8+
9+
const CodeMirror = dynamic(
10+
() => import('react-codemirror2').then(mod => mod.Controlled),
11+
{ ssr: false }
12+
);
913

1014
hljs.registerLanguage('javascript', javascript)
1115

@@ -209,15 +213,15 @@ class Carbon extends React.PureComponent {
209213
light={light}
210214
/>
211215
) : null}
212-
<CodeMirror
213-
ref={this.props.editorRef}
214-
className={`CodeMirror__container window-theme__${config.windowTheme}`}
215-
value={this.props.children}
216-
options={options}
217-
onBeforeChange={this.onBeforeChange}
218-
onGutterClick={this.props.onGutterClick}
219-
onSelection={this.onSelection}
220-
/>
216+
<CodeMirror
217+
ref={this.props.editorRef}
218+
className={`CodeMirror__container window-theme__${config.windowTheme}`}
219+
value={this.props.children}
220+
options={options}
221+
onBeforeChange={this.onBeforeChange}
222+
onGutterClick={this.props.onGutterClick}
223+
onSelection={this.onSelection}
224+
/>
221225
{config.watermark && <Watermark light={light} />}
222226
<div className="container-bg">
223227
<div className="white eliminateOnRender" />

0 commit comments

Comments
 (0)