[DevTools] Don't keep stale root instances we never mounted around (#34504)
Sebastian "Sebbie" Silbermann committed
Sep 16, 2025 at 19:17 UTC
941cd803a7e29c5b2d88d0310ae79f2b2c8c1777
1 file changed
+8
-5
packages/react-devtools-shared/src/backend/fiber/renderer.js
+8
-5
@@ -1516,7 +1516,7 @@ export function attach(
1516
currentRoot = rootInstance;
1517
unmountInstanceRecursively(rootInstance);
1518
rootToFiberInstanceMap.delete(root);
1519
- flushPendingEvents(root);
1519
+ flushPendingEvents();
1520
currentRoot = (null: any);
1521
});
1522
@@ -1541,7 +1541,7 @@ export function attach(
1541
currentRoot = newRoot;
1542
setRootPseudoKey(currentRoot.id, root.current);
1543
mountFiberRecursively(root.current, false);
1544
- flushPendingEvents(root);
1544
+ flushPendingEvents();
1545
currentRoot = (null: any);
1546
});
1547
@@ -2099,7 +2099,7 @@ export function attach(
2099
}
2100
}
2101
2102
- function flushPendingEvents(root: Object): void {
2102
+ function flushPendingEvents(): void {
2103
if (shouldBailoutWithPendingOperations()) {
2104
// If we aren't profiling, we can just bail out here.
2105
// No use sending an empty update over the bridge.
@@ -5349,7 +5349,7 @@ export function attach(
5349
5350
mountFiberRecursively(root.current, false);
5351
5352
- flushPendingEvents(root);
5352
+ flushPendingEvents();
5353
5354
needsToFlushComponentLogs = false;
5355
currentRoot = (null: any);
@@ -5452,6 +5452,9 @@ export function attach(
5452
unmountInstanceRecursively(rootInstance);
5453
removeRootPseudoKey(currentRoot.id);
5454
rootToFiberInstanceMap.delete(root);
5455
+ } else if (!prevWasMounted && !nextIsMounted) {
5456
+ // We don't need this root anymore.
5457
+ rootToFiberInstanceMap.delete(root);
5458
}
5459
5460
if (isProfiling && isProfilingSupported) {
@@ -5475,7 +5478,7 @@ export function attach(
5478
}
5479
5480
// We're done here.
5478
- flushPendingEvents(root);
5481
+ flushPendingEvents();
5482
5483
needsToFlushComponentLogs = false;
5484