From e6cf23ceee14dfdc952baedc75e8058da1f143e7 Mon Sep 17 00:00:00 2001 From: Sebastian Sebbie Silbermann Date: Tue, 16 Sep 2025 15:00:31 +0200 Subject: [PATCH 1/2] [DevTools] Use alternate as previous Fiber when reconciling root --- packages/react-devtools-shared/src/backend/fiber/renderer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-devtools-shared/src/backend/fiber/renderer.js b/packages/react-devtools-shared/src/backend/fiber/renderer.js index 37e1c0a87d15b..ca01ca2135133 100644 --- a/packages/react-devtools-shared/src/backend/fiber/renderer.js +++ b/packages/react-devtools-shared/src/backend/fiber/renderer.js @@ -5398,7 +5398,7 @@ export function attach( rootToFiberInstanceMap.set(root, rootInstance); idToDevToolsInstanceMap.set(rootInstance.id, rootInstance); } else { - prevFiber = rootInstance.data; + prevFiber = rootInstance.data.alternate; } currentRoot = rootInstance; From a387a3fd22fc2c0858c2ec789372e8efa23ae235 Mon Sep 17 00:00:00 2001 From: Sebastian Sebbie Silbermann Date: Tue, 16 Sep 2025 15:41:40 +0200 Subject: [PATCH 2/2] [DevTools] Don't keep stale root instances around we never mounted --- .../src/backend/fiber/renderer.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/react-devtools-shared/src/backend/fiber/renderer.js b/packages/react-devtools-shared/src/backend/fiber/renderer.js index ca01ca2135133..22300ec5f7f99 100644 --- a/packages/react-devtools-shared/src/backend/fiber/renderer.js +++ b/packages/react-devtools-shared/src/backend/fiber/renderer.js @@ -1516,7 +1516,7 @@ export function attach( currentRoot = rootInstance; unmountInstanceRecursively(rootInstance); rootToFiberInstanceMap.delete(root); - flushPendingEvents(root); + flushPendingEvents(); currentRoot = (null: any); }); @@ -1541,7 +1541,7 @@ export function attach( currentRoot = newRoot; setRootPseudoKey(currentRoot.id, root.current); mountFiberRecursively(root.current, false); - flushPendingEvents(root); + flushPendingEvents(); currentRoot = (null: any); }); @@ -2099,7 +2099,7 @@ export function attach( } } - function flushPendingEvents(root: Object): void { + function flushPendingEvents(): void { if (shouldBailoutWithPendingOperations()) { // If we aren't profiling, we can just bail out here. // No use sending an empty update over the bridge. @@ -5349,7 +5349,7 @@ export function attach( mountFiberRecursively(root.current, false); - flushPendingEvents(root); + flushPendingEvents(); needsToFlushComponentLogs = false; currentRoot = (null: any); @@ -5398,7 +5398,7 @@ export function attach( rootToFiberInstanceMap.set(root, rootInstance); idToDevToolsInstanceMap.set(rootInstance.id, rootInstance); } else { - prevFiber = rootInstance.data.alternate; + prevFiber = rootInstance.data; } currentRoot = rootInstance; @@ -5452,6 +5452,9 @@ export function attach( unmountInstanceRecursively(rootInstance); removeRootPseudoKey(currentRoot.id); rootToFiberInstanceMap.delete(root); + } else if (!prevWasMounted && !nextIsMounted) { + // We don't need this root anymore. + rootToFiberInstanceMap.delete(root); } if (isProfiling && isProfilingSupported) { @@ -5475,7 +5478,7 @@ export function attach( } // We're done here. - flushPendingEvents(root); + flushPendingEvents(); needsToFlushComponentLogs = false;