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

Fix Presence component memory leak #3234

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lauri865
Copy link

@lauri865 lauri865 commented Nov 20, 2024

Description

Fixes #3202

Took a while to track this down, but here goes:
When the child of Presence component gets unmounted, stylesRef is not clean up, which in turn prevents the detached nodes from being garbage collected, as it's holding a reference to the node. Affects any radix component that depends on Presence.

  • Tooltip, HoverCard, etc. – leaves a new detached node after every hover/unhover
  • Dialog, Popover, DropdownMenu, etc. – leaves detached nodes around after closing

Note when testing: please build React for production first, as the dev-mode itself can have memory leaks.

Alternative could be to use WeakRef, but I wasn't sure how the Radix team feels about its browser support.

Presence component doesn't unmount itself, and by keeping a reference around for node's styles after the node has unmounted, the node itself cannot ever get garbage collected. This affects pretty much all radix primitive components.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dialog memory leak (detached Dialog.Content)
1 participant