Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Pasting a paragraph breaks trimTextContentFromAnchor #3773

Closed
giacomoran opened this issue Jan 24, 2023 · 12 comments
Closed

Bug: Pasting a paragraph breaks trimTextContentFromAnchor #3773

giacomoran opened this issue Jan 24, 2023 · 12 comments

Comments

@giacomoran
Copy link
Contributor

giacomoran commented Jan 24, 2023

Lexical version: 0.7.6

Steps To Reproduce

  1. Open Lexical Playground with the "Max Length" setting on: https://playground.lexical.dev/?isMaxLength=true
  2. Clear the editor
  3. Paste a paragraph, where text/html in the clipboard is a <p> tag. (You can copy the entire first paragraph at https://lexical.dev/docs/intro)
  4. The text is not pasted. trimTextContentFromAnchor, called by MaxLengthPlugin, crashes as it attempts to remove the root node.

Note that, at https://lexical.dev/docs/intro:

  • if you copy the title along with the first paragraph, it will be pasted correctly in the editor
  • if you copy only a portion of the paragraph, it will be pasted correctly in the editor
@pratik9333
Copy link

Can I work on this bug?

@giacomoran
Copy link
Contributor Author

That would be great! #3775 might be related.

@pratik9333
Copy link

Damn, how are you guys able to notice such bugs? good job!

@pratik9333
Copy link

Are there any volunteers who can assign me this issue?

@thegreatercurve
Copy link
Contributor

Feel free @pratik9333

@SalmanWasiKhan
Copy link

@pratik9333 Is there any progress on this issue?

@777PolarFox777
Copy link

I believe that this line cause the error

$restoreEditorState(editor, prevEditorState);

It looks like this method doesn't work correctly, I'm seeing some Nodes in NodeMap having __next field that points to non-existing nodes and that's where the error occurs: createChildrenArray: node does not exist in nodeMap

@alexkalinins
Copy link

@777PolarFox777 Yes it is caused by $restoreEditorState.

The same error also appears when pressing enter after reaching the input limit.

@CanRau
Copy link
Contributor

CanRau commented Sep 14, 2023

@777PolarFox777 Yes it is caused by $restoreEditorState.

The same error also appears when pressing enter after reaching the input limit.

facing the same issue, interestingly I can't reproduce it in the playground though 🤷🏼

I'm pretty confused now, I actually don't understand how MaxLengthPlugin, trimTextContentFromAnchor doesn't get called yet the error happens and clears the whole editor 🤔

old comment

I believe that this line cause the error

$restoreEditorState(editor, prevEditorState);

It looks like this method doesn't work correctly, I'm seeing some Nodes in NodeMap having __next field that points to non-existing nodes and that's where the error occurs: createChildrenArray: node does not exist in nodeMap

Tried to replace it with editor.setEditorState(prevEditorState) but then realized that my prevEditorState contains non-existing __next nodes

So yea trimTextContentFromAnchor seems to do something shady 😅

@CanRau
Copy link
Contributor

CanRau commented Sep 14, 2023

Has actually been fixed in #4871 and released in v0.12.1
Just tested and works as expected 🥳

So this issue can be closed I guess

@giacomoran
Copy link
Contributor Author

It's still not working for me.

Lexical: 0.12.2 (assuming Lexical Playground uses the latest version)
Chrome on MacOS

Screen.Recording.2023-09-14.at.22.26.17.mp4

@khsily
Copy link
Contributor

khsily commented Sep 19, 2023

It's still not working for me.

Lexical: 0.12.2 (assuming Lexical Playground uses the latest version) Chrome on MacOS

Screen.Recording.2023-09-14.at.22.26.17.mp4

I made a PR for this issue. Please check #5020

@zurfyx zurfyx closed this as completed Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants