lexical icon indicating copy to clipboard operation
lexical copied to clipboard

Fix undo

Open Piechota opened this issue 1 year ago • 6 comments

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

Piechota avatar Jun 24 '24 21:06 Piechota

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

vercel[bot] avatar Jun 24 '24 21:06 vercel[bot]

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

github-actions[bot] avatar Jun 24 '24 21:06 github-actions[bot]

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 avatar Jun 25 '24 10:06 Sahejkm

@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.

Piechota avatar Jun 25 '24 19:06 Piechota

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.

It would be great to get some steps to replicate the crash to understand the issue and fix better

Sahejkm avatar Jun 26 '24 03:06 Sahejkm

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.

Piechota avatar Jun 28 '24 22:06 Piechota

Closing this PR due to staleness! If there are new updates, please reopen the PR.

etrepum avatar Dec 02 '24 19:12 etrepum