lexical
lexical copied to clipboard
Fix undo
When doing undo in document where some text had format != 0 Error was thrown:
TypeError: Cannot assign to read only property '_cachedNodes' of object '#<RangeSelection>'
at RangeSelection.setCachedNodes
at ParagraphNode.getWritable
at ParagraphNode.setTextFormat
at reconcileParagraphFormat
at $reconcileChildrenWithDirection
Basically editorState is readOnly at this point, but we try to write to ParagraphNode when text's format is different from paragraph.
I have copied solution from reconcileBlockDirection
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| lexical | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Jun 28, 2024 10:44pm |
| lexical-playground | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Jun 28, 2024 10:44pm |
size-limit report 📦
| Path | Size |
|---|---|
| lexical - cjs | 28.47 KB (0%) |
| lexical - esm | 28.28 KB (0%) |
| @lexical/rich-text - cjs | 36.86 KB (0%) |
| @lexical/rich-text - esm | 28.08 KB (0%) |
| @lexical/plain-text - cjs | 35.49 KB (0%) |
| @lexical/plain-text - esm | 25.3 KB (0%) |
| @lexical/react - cjs | 38.82 KB (0%) |
| @lexical/react - esm | 29.27 KB (0%) |
Hi Piechota, Thanks for fixing this
- could we add the screenshots / videos to replicate this issue ?
- we should also add a test for this.
@Sahejkm I will add tests later this week as for screenshot/video there isn't much to show with those. Set content with editor.setEditorState() (I missed that part in description and this might be the reason why I don't see this on playground) -> type something -> ctrl+z = error if there was TextNode with format != 0
Tbh I don't understand exactly where this error is coming from (what makes editorState to be readOnly), but there is readOnly check in reconcileBlockDirection too and my guess is it was for the same error.
Tbh I don't understand exactly where this error is coming from (what makes editorState to be readOnly), but there is readOnly check in
reconcileBlockDirectiontoo and my guess is it was for the same error.
It would be great to get some steps to replicate the crash to understand the issue and fix better
Small update. I couldn't reproduce this with simple unit test. So either I am doing something wrong (most likely) or it has something to do with input method. I will have to investigate further.
Closing this PR due to staleness! If there are new updates, please reopen the PR.