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

[lexical-table] Bug Fix: Prevent error if pasted table has empty row #7057

Merged
merged 2 commits into from
Jan 16, 2025

Conversation

amanharwara
Copy link
Contributor

Description

Currently, if a table was pasted that has an empty row, the $tableTransform would throw an error. This is because in $computeTableMapSkipCellCheck, an array for a row is only initialized inside the loop that goes through its children. This causes there to be a gap in the gridMap since an array for the empty row never gets initialized, which then causes gridMap[i] to be undefined and throw an error.

This PR fixes this by making sure an empty array is initialized at the index of the empty row, which in turn will be filled with the necessary amount of cells by $tableTransform

Test plan

Added e2e test to cover this scenario

Before

image

After

image

Copy link

vercel bot commented Jan 16, 2025

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 Jan 16, 2025 5:04pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 16, 2025 5:04pm

@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 Jan 16, 2025
Copy link

github-actions bot commented Jan 16, 2025

size-limit report 📦

Path Size
lexical - cjs 29.03 KB (0%)
lexical - esm 28.87 KB (0%)
@lexical/rich-text - cjs 37.97 KB (0%)
@lexical/rich-text - esm 30.92 KB (0%)
@lexical/plain-text - cjs 36.52 KB (0%)
@lexical/plain-text - esm 28.13 KB (0%)
@lexical/react - cjs 39.79 KB (0%)
@lexical/react - esm 32.28 KB (0%)

Comment on lines 859 to 861
if (row.getChildrenSize() === 0) {
tableMap[rowIdx] = [];
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this is correct regarding rowspan, but you can initialize startMapRow here which will have the same effect and should be correct (at least with regard to that constraint). You'll have to remove the initialization below but I can't put a suggestion on code you didn't change in the review

Suggested change
if (row.getChildrenSize() === 0) {
tableMap[rowIdx] = [];
}
const startMapRow = getMapRow(rowIdx);

@etrepum etrepum added this pull request to the merge queue Jan 16, 2025
Merged via the queue into facebook:main with commit f6377a3 Jan 16, 2025
40 checks passed
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.

3 participants