@@ -37,8 +37,8 @@ function ReactCodeMirror(props = {}, ref) {
37
37
38
38
// http://codemirror.net/doc/manual.html#config
39
39
async function setOptions ( instance , opt = { } ) {
40
- if ( typeof opt === 'object' ) {
41
- const mode = CodeMirror . findModeByName ( opt . mode ) ;
40
+ if ( typeof opt === 'object' && window ) {
41
+ const mode = CodeMirror . findModeByName ( opt . mode || '' ) ;
42
42
if ( mode && mode . mode ) {
43
43
await import ( `codemirror/mode/${ mode . mode } /${ mode . mode } .js` ) ;
44
44
}
@@ -54,7 +54,7 @@ function ReactCodeMirror(props = {}, ref) {
54
54
}
55
55
56
56
useEffect ( ( ) => {
57
- if ( ! editor ) {
57
+ if ( ! editor && window ) {
58
58
// 生成codemirror实例
59
59
const instance = CodeMirror . fromTextArea ( textareaRef . current , { ...defaultOptions , ...options } ) ;
60
60
const eventDict = getEventHandleFromProps ( ) ;
@@ -71,29 +71,29 @@ function ReactCodeMirror(props = {}, ref) {
71
71
setOptions ( instance , { ...defaultOptions , ...options } ) ;
72
72
}
73
73
return ( ) => {
74
- if ( editor ) {
74
+ if ( editor && window ) {
75
75
editor . toTextArea ( ) ;
76
76
setEditor ( undefined ) ;
77
77
}
78
78
}
79
79
} , [ ] ) ;
80
80
81
81
useMemo ( ( ) => {
82
- if ( ! editor ) return ;
82
+ if ( ! editor || ! window ) return ;
83
83
const val = editor . getValue ( ) ;
84
84
if ( value !== undefined && value !== val ) {
85
85
editor . setValue ( value ) ;
86
86
}
87
87
} , [ value ] ) ;
88
88
89
89
useMemo ( ( ) => {
90
- if ( ! editor ) return ;
90
+ if ( ! editor || ! window ) return ;
91
91
editor . setSize ( width , height ) ;
92
92
} , [ width , height ] ) ;
93
93
94
94
95
95
useMemo ( ( ) => {
96
- if ( ! editor ) return ;
96
+ if ( ! editor || ! window ) return ;
97
97
setOptions ( editor , { ...defaultOptions , ...options } ) ;
98
98
} , [ options ] ) ;
99
99
0 commit comments