Skip to content

Bug: Detached nodes are created when portal is rendered conditionally #33175

Open
@kart-c

Description

@kart-c

I am creating a simple tooltip where tooltip content is rendered in a portal when hovered upon. This creates detached nodes. Added a github test repo and videos of the same.

React version:
"react": "^19.0.0",
"react-dom": "^19.0.0"

Steps To Reproduce

  1. Clone the repo. repo link
  2. Use TooltipWithoutKey in App.tsx file.
  3. Hover multiple times.
  4. Take heap snapshot.
  5. Detached nodes are noticed.
  6. Now use TooltipWithKey in App.tsx file.
  7. No detached nodes noticed.

Also tried using the 3rd key argument for createPortal, but it did not work. Which is why the Fragment with key prop was used.

Link to code example: https://github.com/kart-c/react-dom-issue

TooltipWithoutKey

tooltip_without_key.mp4

TooltipWithKey

tooltip_with_key.mp4

The current behavior

Detached nodes are created.

The expected behavior

Detached nodes should not be created.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions