Skip to content

Button with a tooltip throws NotFoundError: removeChild when it unmounts inside a Lexical decorator #7580

Closed

Description

@potatowagon

What happens

A Button carrying a tooltip throws when it unmounts inside a Lexical
decorator node:

NotFoundError: Failed to execute 'removeChild' on 'Node':
The node to be removed is not a child of this node.

The decorator keeps working afterwards, but the error reaches the console (and
any test asserting a clean console), and the story is reported as failing to
render by Storybook's own error overlay.

Where I hit it

Building an image plugin for the RichText/RichTextEditor Playground story
(#7579). A DecoratorNode renders the image and, while the node is selected,
a row of Astryx Buttons beside it. Selecting the image mounts that row;
clicking elsewhere unmounts it, and the throw lands there.

Minimal shape

class ImageNode extends DecoratorNode<ReactNode> {
  decorate() {
    return <ImageComponent nodeKey={this.getKey()} /* … */ />;
  }
}

function ImageComponent({nodeKey}) {
  const [isSelected] = useLexicalNodeSelection(nodeKey);
  return (
    <span>
      <img /* … */ />
      {isSelected && <Button size="sm" label="Smaller" tooltip="Narrow it" />}
    </span>
  );
}

Select the image (the button mounts), then click into the text (the button
unmounts) → the error.

What isolates it to tooltip

Three runs of the same scenario, same story, same build, each verified in
Chromium with the console collected:

Controls rendered in the decorator Result on unmount
Astryx Button with tooltip NotFoundError: removeChild
Astryx Button without tooltip clean
Plain <button> clean

The same tooltipped buttons mounted outside a decorator — in the editor's
toolbar, unmounted by toggling the toolbar off — also unmount cleanly. So it is
the combination of tooltip and the decorator subtree, not tooltip alone.

Guess at the mechanism

A Lexical decorator is a React portal into a DOM element Lexical owns and
removes on its own schedule, so React unmounts the subtree against a parent
that may already be detached. Anything the tooltip layer relocates (top layer,
anchor positioning) is then removed from a node that is no longer its parent.

Environment

main at 22743455aa, lexical 0.52.0, React 19.2.7, Chromium via Playwright.

Workaround

Drop tooltip from buttons rendered inside a decorator; #7579 does that, and
its labels carry the meaning on their own.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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