mdx-editor / editor

A rich text editor React component for markdown
https://mdxeditor.dev
MIT License
1.57k stars 124 forks source link

[BUG] Cannot assign to read only property '_cachedNodes' of object '#<RangeSelection>' when I open the editor and undo some texts #485

Open bloodteller123 opened 1 month ago

bloodteller123 commented 1 month ago

If you want to ask for support or request features, sponsor the project and contact me over email.

Describe the bug I have a markdown string which is built by GPT (returned from some API calls), it's passed to the Editor via markdown props as the initial markdown. If I perform undo operation when the editor is open, I can see it's popping error.

Reproduction https://codesandbox.io/p/sandbox/test-lv7m8w?file=%2Fsrc%2FApp.tsx please see the md2 string; and please kindly ignore and close the reference error page :)

To Reproduce Steps to reproduce the behavior:

  1. Type a few words in the editor
  2. Then do ctrl + Z or click on undo button
  3. See error
  4. but if I close the error page and type a few more words and undo, everything works as normal

Expected behavior no error

Desktop (please complete the following information):

Additional context The markdown string is constructed by GPT, and I wondered if it's because of some special characters that cause the error? because I tried it with the markdown from your example, and normal text, everything works fine...

Besides, is there a way to suppress the error page? I know in Lexical we can config the onError method in initialConfig of LexicalComposer which doesn't pop the error page when the error occurs by console.log(). Thank you very much.

petyosi commented 1 month ago

I think this is a bug in Lexical. This looks the same: https://github.com/facebook/lexical/issues/3535 - and it looks like the PR never got merged. Your markdown is fine, by the way. Even if I reduce it down to:

let md2 = `**To:**`;

the error still happens. My gut feel says something does not work with bold formatting being the beginning of the paragraph.

I will see what I can do, but in the meantime, you can also try to reproduce the problem in a plain Lexical environment and get something going there.