react-codemirror icon indicating copy to clipboard operation
react-codemirror copied to clipboard

Waiting to render when typed quickly

Open ozanbatuhanceylan opened this issue 2 years ago • 5 comments

Hi, I am facing an issue about performance. When i type quickly i have to wait about 200ms to 500ms for the editor to render my expressions. I have checked the example page of repository (https://uiwjs.github.io/react-codemirror/) and realized that the same issue occurs there.

Is there a way to improve performance while i am consuming the wrapper or is this a render issue in the implementation of wrapper?

PS. I don't know if it is related but when i type a character cm-editor regenerate a class name that contains "min-height, height, max-height, width, min-width, max-width" css rules. Is it necessary to regenerate class name but i think it is render impact on DOM

Thanks in advance

ozanbatuhanceylan avatar Jan 30 '23 00:01 ozanbatuhanceylan

Hi,

I have the same problem. I think it's because each render creates a new theme object. This problem exists in useCodeMirror.ts.

The solution is to avoid creating a theme (EditorView.theme) in the component or using useMemo.

puckwang avatar Feb 04 '23 00:02 puckwang

@puckwang @ozanbatuhanceylan

import CodeMirror from '@uiw/react-codemirror';

export default function App() {
  const [code, setCode] = useState('');
  return (
    <CodeMirror
      value="console.log('hello world!');"
      height="200px"
-      onChange={setCode}
    />
  );
}

https://codesandbox.io/embed/react-codemirror-example-codemirror-6-uiwjs-react-codemirror-issues-390-forked-g3rbtw?fontsize=14&hidenavigation=1&theme=dark

It's a matter of controlled value props

@puckwang @ozanbatuhanceylan

jaywcjlove avatar Feb 04 '23 13:02 jaywcjlove

i'm having the same issue with controlled value props. editor lags when we type more text

kasvith avatar Oct 13 '23 17:10 kasvith

are there any workarounds @jaywcjlove

kasvith avatar Oct 13 '23 17:10 kasvith

i think we can solve this by introducing an initialValue prop. this way we wont need to do a document update as in here

https://github.com/uiwjs/react-codemirror/blob/6f14c51c109333acbc394a09d981b411ac37d397/core/src/useCodeMirror.ts#L164

kasvith avatar Oct 13 '23 17:10 kasvith