Skip to content

[lexical-table] Bug Fix: Add fallback selection to InsertTableCommand - #7316

Merged
etrepum merged 6 commits into
meta:mainfrom
patrick-atticus:table-insert-fallback-selection
Mar 21, 2025
Merged

etrepum merged 6 commits into
meta:mainfrom
patrick-atticus:table-insert-fallback-selection

Conversation

@patrick-atticus

Copy link
Copy Markdown
Contributor

Description

If you try to insert a table asynchronously when the editor is not focused, the table is not inserted (because there is no selection)

This can happen if you focus an input field (like row count in the playground), and then dispatch INSERT_TABLE_COMMAND async.

Screenshot 2025-03-12 at 3 01 13 pm

Tables are not inserted async in the playground so it's not a problem, but it can easily be reproduced by wrapping the insert command in a setTimeout in packages/lexical-playground/src/plugins/TablePlugin.tsx

This PR adds a fallback to $getPreviousSelection() in the table insert command handler. Same as #4570

Note that that actual insertion uses $insertNodeToNearestRoot, which already uses the same fallback. This change simply prevents the command from exiting early.

@vercel

vercel Bot commented Mar 12, 2025 •

Copy link
Copy Markdown

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

@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 Mar 12, 2025

@etrepum etrepum left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Adding a test would be a good idea, since as you said the playground doesn’t do this there’s no confirmation that this fixes anything

@patrick-atticus

Copy link
Copy Markdown
Contributor Author

Unfortunately I could not reproduce this in the headless unit test environment.

I can't do an e2e test without changing playground behaviour. I updated the playground so now the insert is async and the button renders as disabled, which is nice when you insert a huge table and it takes a moment.

Now the table tests (eg Can a table be inserted from the toolbar) will fail without the updated $insertTableCommandListener.

I'll understand if you don't want these playground changes.

@patrick-atticus
patrick-atticus requested a review from etrepum March 12, 2025 09:28
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Mar 12, 2025
@patrick-atticus

Copy link
Copy Markdown
Contributor Author

Earlier I was missing discreet updates to get the test sequencing correct.

I've also added a test for basic table insertion. The other tests checked that nested tables was NOT being inserted, and since the commands weren't registered, no tables could be inserted.

@patrick-atticus
patrick-atticus requested a review from etrepum March 17, 2025 05:36
@etrepum
etrepum added this pull request to the merge queue Mar 21, 2025
Merged via the queue into meta:main with commit 55cc35f Mar 21, 2025

This branch was successfully deployed

2 active deployments
Preview – lexical-playground — bfec5f8a Deployed Mar 21, 2025 by vercel[bot]
Preview – lexical — bfec5f8a Deployed Mar 21, 2025 by vercel[bot]
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. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants