Skip to content

Bug: selection points to missing nodes after calling $deleteTableRow__EXPERIMENTAL() on all table rows #7140

@mike-atticus

Description

@mike-atticus

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    tablesRelates to Lexical Tables

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions