Skip to content

[DevTools] Fix memory leak when unmounting hoistables#35741

Merged
eps1lon merged 2 commits intofacebook:mainfrom
eps1lon:sebbie/rdt-hoistables
Feb 10, 2026
Merged

[DevTools] Fix memory leak when unmounting hoistables#35741
eps1lon merged 2 commits intofacebook:mainfrom
eps1lon:sebbie/rdt-hoistables

Conversation

@eps1lon
Copy link
Collaborator

@eps1lon eps1lon commented Feb 10, 2026

Summary

For Host Hoistables we have may have many devtools instances to choose from as the nearest instance since React Float may have deduplicated the public host instance. We keep an internal map from the public host instance to the chosen devtools instance. When we were unmounting a Host Hoistable, we pick the next Fiber that's also referencing the same public host instance.

Unfortunately we were using the wrong values when moving those pointers. This wasn't caught by Flow since our HostInstance type is any object so you can assign anything to it and assign it to anything (here we assigned a DevToolsInstance to a HostInstance).

We could improve type safety for those operations but it's quite involved. It's the only bug where we currently accidentally assign these two types. If this happens more often, we can harden the types.

Also ensures element inspection works when unmounting Hoist Hoistables. You'd have to actually inspect the DOM node to notice the bug. The memory leak you always get so I choose that bug as the headline.

Found with Claude + Opus 4.6

How did you test this change?

  • Added test (1st commit has previous behavior)

@meta-cla meta-cla bot added the CLA Signed label Feb 10, 2026
@github-actions github-actions bot added the React Core Team Opened by a member of the React Core Team label Feb 10, 2026
@eps1lon eps1lon force-pushed the sebbie/rdt-hoistables branch from 731b9b6 to 2ae2122 Compare February 10, 2026 11:50
@eps1lon eps1lon requested a review from hoxyq February 10, 2026 11:50
@eps1lon eps1lon marked this pull request as ready for review February 10, 2026 11:50
@gvago
Copy link

gvago commented Feb 10, 2026

Hey @hoxyq, how can we get Qodo agentic github review installed in the repo?

@eps1lon eps1lon merged commit f23aa1d into facebook:main Feb 10, 2026
237 checks passed
@eps1lon eps1lon deleted the sebbie/rdt-hoistables branch February 10, 2026 12:20
github-actions bot pushed a commit to code/lib-react that referenced this pull request Feb 15, 2026
github-actions bot pushed a commit to code/lib-react that referenced this pull request Feb 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants