From 2eee6f047b6fde27a205c5d45b3afe74c5490082 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 12 Mar 2026 18:22:52 +0800 Subject: [PATCH] fix(DevTools): handle race condition when adding fibers during page reload When a page reloads during profiling, DevTools may receive operations from both the old and new renderer. This can cause the same fiber ID to be added twice, which previously threw an error. This fix removes the existing node before adding a new one, allowing the profiling to continue gracefully. Fixes #36006 --- .../src/devtools/views/Profiler/CommitTreeBuilder.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/react-devtools-shared/src/devtools/views/Profiler/CommitTreeBuilder.js b/packages/react-devtools-shared/src/devtools/views/Profiler/CommitTreeBuilder.js index 02ecc98ec6d1..c5ed60c102ca 100644 --- a/packages/react-devtools-shared/src/devtools/views/Profiler/CommitTreeBuilder.js +++ b/packages/react-devtools-shared/src/devtools/views/Profiler/CommitTreeBuilder.js @@ -201,10 +201,11 @@ function updateTree( i += 3; + // If the node already exists, it may be a race condition when the page + // reloads during profiling. In this case, remove the old node first + // before adding the new one. if (nodes.has(id)) { - throw new Error( - `Commit tree already contains fiber "${id}". This is a bug in React DevTools.`, - ); + nodes.delete(id); } if (type === ElementTypeRoot) {