Skip to content

[lexical-y] Bug: An emptied non-simple text node and root NodeState stay in the editing client only #9789

Open

Description

@zurfyx

@lexical/y does not store some node state an editor shows, so the editing client keeps it while every other client and a fresh read of the document do not. Found by review of the binding; both reproduce with ordinary local edits on main.

1. An emptied text node that is not simple text. setTextContent('') on a token or segmented TextNode, a TextNode subclass, or a CodeHighlightNode leaves the editor with an empty node (its class, mode, format, style and any NodeState). Lexical's normalization removes only empty simple text nodes, and the binding writes text as runs of characters, which an empty node has none of: the node is never stored, nothing reads it back, and no warning is raised. Peers and a fresh reader have no node there.

editor.update(() => {
  const token = $getRoot().getLastChildOrThrow().getFirstChildOrThrow(); // a token TextNode
  token.setTextContent('');
  $setState(token, someState, 'value');
});
// this editor: paragraph(token "" with someState); peers and a fresh reader: paragraph()

2. NodeState on the root. $setState($getRoot(), state, value) stays in the editor that set it: the binding stores the root's children, not its own fields or NodeState. Lexical documents root NodeState as document metadata.

Expected: either the binding stores these, or it reads them back on the editing client after writing, so that no client keeps state the document does not have. Cells pinning both as test.fails will reference this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions