-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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: Add fallback selection to InsertTableCommand #7316
base: main
Are you sure you want to change the base?
[lexical-table] Bug Fix: Add fallback selection to InsertTableCommand #7316
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
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
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 I'll understand if you don't want these playground changes. |
setIsDisabled(true); | ||
// Large tables can take a moment. Defer insert to render button disabled | ||
setTimeout(() => { | ||
activeEditor.dispatchCommand(INSERT_TABLE_COMMAND, { | ||
columns, | ||
rows, | ||
}); | ||
|
||
onClose(); | ||
onClose(); | ||
}, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's roll this change back, I don't see a good reason to demonstrate this anti-pattern in playground code that people will be copying. Table creation and rendering isn't async there's no real utility to disabling anything since the UI isn't going to be responsive while any of that is happening.
I don't see why you couldn't do this in a unit test with $setSelection(null); editor.dispatchCommand(INSERT_TABLE_COMMAND, …);
given a previous update that had a selection.
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.
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 #4570Note that that actual insertion uses
$insertNodeToNearestRoot
, which already uses the same fallback. This change simply prevents the command from exiting early.