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

fix(tables): Add missing paragraph node when copying empty cells from external resources #5670

Merged

Conversation

vect-spasquereau
Copy link
Contributor

@vect-spasquereau vect-spasquereau commented Feb 29, 2024

Fixes #5662

Issue

When copy/pasting a table from external sources (google doc, google spreadshet, e.g.), an empty cell is created with no child node :

image

Change

Return after callback in convertTableCellNodeElement to insert paragraph if the cell is empty :

image

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 29, 2024
Copy link

vercel bot commented Feb 29, 2024

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 Mar 4, 2024 5:23pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 4, 2024 5:23pm

@StyleT
Copy link
Contributor

StyleT commented Mar 1, 2024

Hi! Do you think this can be covered with test?

@vect-spasquereau
Copy link
Contributor Author

vect-spasquereau commented Mar 4, 2024

hey @StyleT , I implemented a test for my fix. As table nodes are not massively covered, I added a bunch of tests for rows and cells too.

Copy link
Member

@zurfyx zurfyx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. However, the paragraph will be automatically created upon typing, which resembles the same behavior as when you type on an empty editor (only a RootNode). Do you mind expanding on the problem you're trying to solve here?

@vect-spasquereau
Copy link
Contributor Author

@zurfyx unfortunately no, the paragraph node is not created upon typing in an empty cell 😕 It creates a text node, not a paragraph node:

image

The issue is when you focus an empty table cell node and that you press "Enter". There are some methods involved in LexicalSelection that are supposed to find the right position where the new paragraph should be inserted. These methods (removeTextAndSplitBlock and splitNodeAtPoint) create an infinite loop in this specific case that crashed lexical. I don't want to modify these functions because I'm not aware of the impacts it could have. Having a paragraph inside empty cells is fixing this issue.

Also, I noticed that a paragraph node was explicitely created in cells in methods like $createTableNodeWithDimensions, $insertTableRow, $insertTableColumn, etc. So I assumed it was the right thing to do 🙂

Copy link
Contributor

@acywatson acywatson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is reasonable. Will let @zurfyx confirm that he doesn't have further objections.

@zurfyx
Copy link
Member

zurfyx commented Mar 6, 2024

@zurfyx unfortunately no, the paragraph node is not created upon typing in an empty cell 😕 It creates a text node, not a paragraph node:

Ouch, you're right, I remember this working in the past...

@zurfyx zurfyx merged commit 9f84191 into facebook:main Mar 6, 2024
45 checks passed
@vect-spasquereau
Copy link
Contributor Author

thx 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Inserting a table from external source can lead to Lexical crash
5 participants