Skip to content

Commit 17494f9

Browse files
authored
Debounce the resizer of codemirror (codesandbox#3340)
1 parent 1e891aa commit 17494f9

File tree

1 file changed

+8
-2
lines changed
  • packages/app/src/app/components/CodeEditor/CodeMirror

1 file changed

+8
-2
lines changed

packages/app/src/app/components/CodeEditor/CodeMirror/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { getCodeMirror } from 'app/utils/codemirror';
1212
import CodeMirror from 'codemirror';
1313
import { listen } from 'codesandbox-api';
1414
import * as React from 'react';
15+
import { debounce } from 'lodash-es';
1516
import { withTheme } from 'styled-components';
1617
// eslint-disable-next-line
1718
import LinterWorker from 'worker-loader?publicPath=/&name=monaco-linter.[hash:8].worker.js!app/overmind/effects/vscode/LinterWorker/index';
@@ -54,6 +55,7 @@ class CodemirrorEditor extends React.Component<Props, State> implements Editor {
5455
this.settings = props.settings;
5556

5657
this.codeSandboxListener = this.setupCodeSandboxListener();
58+
this.resizeEditor = debounce(this.resizeEditor, 30);
5759
}
5860

5961
setupCodeSandboxListener = () => listen(this.handleMessage);
@@ -79,8 +81,7 @@ class CodemirrorEditor extends React.Component<Props, State> implements Editor {
7981
this.props.width !== nextProps.width ||
8082
this.props.height !== nextProps.height
8183
) {
82-
// eslint-disable-next-line no-unused-expressions
83-
this.codemirror?.refresh();
84+
this.resizeEditor();
8485
return true;
8586
}
8687

@@ -111,6 +112,11 @@ class CodemirrorEditor extends React.Component<Props, State> implements Editor {
111112
});
112113
}
113114

115+
resizeEditor() {
116+
// eslint-disable-next-line no-unused-expressions
117+
this.codemirror?.refresh();
118+
}
119+
114120
setErrors = (errors: Array<ModuleError>) => {
115121
const codeLines = this.codemirror.getValue().split('\n');
116122

0 commit comments

Comments
 (0)