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: selection points to missing nodes after calling $deleteTableRow__EXPERIMENTAL() on all table rows #7140

Open
mike-atticus opened this issue Feb 6, 2025 · 2 comments
Labels
tables Relates to Lexical Tables

Comments

@mike-atticus
Copy link
Contributor

mike-atticus commented Feb 6, 2025

Calling $deleteTableRow__EXPERIMENTAL() when all table rows are selected produces an editor state (processed by update listeners) that has an invalid selection. The selection points to nodes that have been removed from the editor, so if you call $getSelection()?.getNodes() you will get an error Point.getNode: node not found.

Note: in the recording below the rendered HTML table doesn't show the selection, but the tree view below the editor shows the table cells are getting selected.

CleanShot.2025-02-06.at.16.45.50.mp4

Lexical version: 0.23.1

Steps To Reproduce

  1. Have an editor state with a table and at least one other sibling node before it (e.g. paragraph).
  2. Have an update listener that calls $getSelection?.getNodes() on every update.
  3. Select all rows of the table, then take an action that runs $deleteTableRow__EXPERIMENTAL().
  4. Observe the error Point.getNode: node not found is thrown.

Link to code example: https://stackblitz.com/edit/facebook-lexical-akmwfitx?file=src%2FApp.tsx

The current behavior

The error Point.getNode: node not found is thrown because the selection is pointing to nodes that have been removed from the document.

The expected behavior

The selection should be fixed up (pointing to valid nodes) before update listeners are called with new updates.

Impact of fix

The most severe impact of this bug exists when you also use CollaborationPlugin, as this error causes Lexical and the Yjs doc to get out of sync. The table deletion doesn't propagate to the Yjs doc, so until the page is refreshed there is risk that user edits are corrupting the document in this unexpected state, and upon refresh users will see the table re-appear unexpectedly.

As a workaround, the error can be caught and handled to avoid this problem.

@etrepum
Copy link
Collaborator

etrepum commented Feb 6, 2025

I haven't fixed the problem but here are the relevant changes to the theme so you can see the selection properly

https://stackblitz.com/edit/facebook-lexical-akmwfitx?file=src%2Fstyles.css,src%2FExampleTheme.ts,index.html,src%2Fmain.tsx

@mike-atticus
Copy link
Contributor Author

Thanks! Have updated the link in the original description.

@etrepum etrepum added the tables Relates to Lexical Tables label Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tables Relates to Lexical Tables
Projects
None yet
Development

No branches or pull requests

2 participants