Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Waiting to render when typed quickly #449

Open
ozanbatuhanceylan opened this issue Jan 30, 2023 · 5 comments
Open

Waiting to render when typed quickly #449

ozanbatuhanceylan opened this issue Jan 30, 2023 · 5 comments

Comments

@ozanbatuhanceylan
Copy link

ozanbatuhanceylan commented Jan 30, 2023

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

@puckwang
Copy link

puckwang commented Feb 4, 2023

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.

@jaywcjlove
Copy link
Member

@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 added a commit that referenced this issue Feb 4, 2023
github-actions bot pushed a commit that referenced this issue Feb 4, 2023
@kasvith
Copy link

kasvith commented Oct 13, 2023

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

@kasvith
Copy link

kasvith commented Oct 13, 2023

are there any workarounds @jaywcjlove

@kasvith
Copy link

kasvith commented Oct 13, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants