Repository navigation
Description
Website or app
Self-contained repro below: one HTML file that loads the React 19.3.0 production build from esm.sh. Serve it from any static server (for example python3 -m http.server) and open it over http.
Repro steps
- Install React Developer Tools 8.0.0 from the Chrome Web Store. Leave the browser's DevTools closed.
- Open the page below and click "Run 3,000 updates". Each update replaces the
<span>rendered by each of 20 components that stay mounted, so 60,000<span>elements and their 60,000 text nodes are removed from the page. - Open DevTools, then Memory, take a heap snapshot and filter by "Detached". About 60,000 detached
<span>elements are still in memory. With the extension disabled there are none.
index.html
<!doctype html>
<meta charset="utf-8">
<title>React DevTools host-instance map repro</title>
<div id="root"></div>
<button id="run">Run 3,000 updates</button> <span id="out"></span>
<script type="importmap">
{ "imports": {
"react": "https://esm.sh/[email protected]",
"react-dom": "https://esm.sh/[email protected][email protected]",
"react-dom/client": "https://esm.sh/[email protected]/[email protected]"
} }
</script>
<script type="module">
import { createElement as h } from 'react';
import { flushSync } from 'react-dom';
import { createRoot } from 'react-dom/client';
// ?p=keyed (default): a mounted component replaces its <span> with a new keyed one.
// ?p=conditional: a mounted component shows and hides its <span>.
// ?p=unmount (control): the component that renders the <span> unmounts with it.
const p = new URLSearchParams(location.search).get('p') || 'keyed';
const Leaf = () => h('span', null, 'x');
const Item = ({ n }) =>
p === 'keyed' ? h('span', { key: n }, 'x')
: p === 'conditional' ? (n % 2 ? h('span', null, 'x') : null)
: (n % 2 ? h(Leaf) : null);
const App = ({ n }) => h('div', null, Array.from({ length: 20 }, (_, i) => h(Item, { key: i, n: n + i })));
const root = createRoot(document.getElementById('root'));
let n = 0;
flushSync(() => root.render(h(App, { n })));
document.getElementById('run').onclick = () => {
for (let i = 0; i < 3000; i++) { n++; flushSync(() => root.render(h(App, { n }))); }
document.getElementById('out').textContent = `${n} updates`;
};
</script>DOM nodes still in memory after the 3,000 updates and a forced GC (CDP HeapProfiler.collectGarbage, then Memory.getDOMCounters), in headless Brave 1.96.60 (Chromium 154) on macOS:
Pattern (?p=) |
Without the extension | With React DevTools 8.0.0 |
|---|---|---|
keyed: a mounted component replaces its <span> with a new keyed one |
2 | 119,962 of the 120,000 removed nodes |
conditional: a mounted component shows and hides its <span> |
2 | 59,982 of 60,000 |
unmount (control): the component that renders the <span> unmounts with it |
2 | 2 |
The baseline of 2 is the same in every pattern, with or without the extension (the page writes its result text). With the extension, the hook reports one renderer and one renderer interface, although no DevTools panel was ever opened. An earlier run with a bundled React 19.1.0 page gave the same result: 119,960 and 59,980 nodes kept, and 0 for the control.
What seems to happen
From reading renderer.js at b618bbb:
- The extension's
installHook.jsbundles the fiber backend (its source map listsreact-devtools-shared/src/backend/fiber/renderer.js), so the renderer is attached as soon as react-dom registers with the hook. That happens in production builds too, with no frontend connected. - On mount, each
HostComponentandHostTextfiber goes intopublicInstanceToDevToolsInstanceMapthroughaquireHostInstance(reconcilingParent, fiber.stateNode)(L3449-L3458, L304-L322).HostTextis always filtered, andHostComponentis filtered by the default component filters, so these fibers have no DevTools instance of their own. The map's value is the nearest tracked instance. releaseHostInstanceis reached only fromuntrackFiber(L1234-L1275) and from the persistent-mode clone path.untrackFiberruns when a tracked instance unmounts, and walks only that fiber's current filtered children. A host fiber that React deletes while its nearest tracked component stays mounted is never inremainingReconcilingChildren(L2585-L2611), because that list holds DevTools instances. So its entry is never released, and later unmounting the owner does not reach it either. The map then keeps the detached element, its subtree and the DevTools instance until the page reloads.
The unmount control row fits this: there the <span> is released with its own component.
Impact
A long-lived page that swaps or streams content keeps growing for as long as it is open. We hit it in a production web app that reveals streamed text in per-character spans: a Brave tab on Windows reached about 16 GB over a few hours, with the extension installed and DevTools closed. In a 6-minute soak of that app with the extension loaded, DOM nodes in memory after a forced GC went from 7,372 to 483,534; with the hook disabled before react-dom loads, they went from 8,108 to 4,397.
Workaround: we set window.__REACT_DEVTOOLS_GLOBAL_HOOK__.isDisabled = true (when the hook exists) before react-dom loads in production builds. React then never registers, and nothing is kept.
Possible directions (untested): release the host instances of a deleted subtree when the reconciler deletes it, or key the map weakly (the TODO in untrackFiber mentions a WeakMap).
Related: #37752 (a different miss in the same map, for Fabric's lazily created public instances) and #31266 (pages slow with DevTools closed).
How often does this bug happen?
Every time
Activity
SuryaNarayana-C-K commentedon Oct 9, 2026
Hi! I'd like to work on this issue.
I've read through the reproduction steps and the explanation of how detached DOM nodes may remain referenced by
publicInstanceToDevToolsInstanceMap.I'd like to investigate the host-instance cleanup path, identify the root cause, and add a regression test before implementing a fix.
Would it be possible to assign this issue to me? I'm happy to follow the repository's contribution guidelines and discuss the proposed approach before opening a PR.
Thank you!