react-markdown-editor icon indicating copy to clipboard operation
react-markdown-editor copied to clipboard

Editor becomes unresponsive when content is long

Open tnhu opened this issue 1 year ago • 6 comments

Try on https://uiwjs.github.io/react-markdown-editor/ with a very long document (Let's say you duplicate the content until it reaches 1000 lines), the editor becomes slower and slower. If you double or triple the lines, it becomes very unresponsive. Type something and it shows up after some seconds.

I tested the same contents on https://codemirror.net/try/?example=Markdown%20code%20block%20highlighting. It does not have the same problem. I guess the issue stays in this library's implementation.

Note that I tested with Preview OFF, plus under an incognito Chrome window.

tnhu avatar Apr 10 '23 20:04 tnhu

https://github.com/uiwjs/react-markdown-editor/blob/2d3f45079c79616b867ef03681a8ba9799169921/src/index.tsx#L192-L198

@tnhu This is due to the rendering of long text by react-markdown. Use renderPreview to lazily load and display the markdown text.

jaywcjlove avatar Apr 11 '23 15:04 jaywcjlove

@jaywcjlove I pass renderPreview as an empty function. Test locally and the slowness is still there... Also FYI, I use 5.11.1.

tnhu avatar Apr 18 '23 20:04 tnhu

https://codesandbox.io/embed/react-markdown-editor-https-github-com-uiwjs-react-markdown-editor-issues-200-zsdt58?fontsize=14&hidenavigation=1&theme=dark

@tnhu Quick speed boost if you render custom

<MarkdownEditor
  height={300}
  value={markdown}
+  renderPreview={() => <div />}
/>

jaywcjlove avatar Apr 21 '23 03:04 jaywcjlove

To improve performance, is it possible to disable renderPreview completely while preview section is not visible? @jaywcjlove

yusufozturk avatar Aug 03 '23 23:08 yusufozturk

@yusufozturk

import React from 'react';
import MarkdownEditor from '@uiw/react-markdown-editor';

const mdStr = `# This is a H1  \n## This is a H2  \n###### This is a H6`;

const Dome = () => {
  return (
    <MarkdownEditor
      value={mdStr}
+      renderPreview={() => null}
      onChange={(value, viewUpdate) => {

      }}
    />
  )
};

jaywcjlove avatar Aug 04 '23 01:08 jaywcjlove

🤦‍♂️ thanks 😄🙏

yusufozturk avatar Aug 04 '23 07:08 yusufozturk