mdx-editor / mdx-editor/editor

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

Open
#485 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
3.7k
Forks
307
Avg merge
14h 22m
Merged PRs (30d)
5

Description

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

  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • I have read the documentation and cannot find an answer.

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):

  • OS: MacOs
  • Browser: Chrome

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked CodeSandbox reproduction, especially the md2 string and the undo steps. Trace how the initial markdown is loaded into the editor and how the undo button or Ctrl+Z reaches the Lexical selection state. Done means the reproduction no longer raises the _cachedNodes error while undoing, with normal text and the reported markdown both working.

Written by the indexing model from the issue text.

Assessment

Tech stack
markdown, react, typescript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.