Skip to content

[DevTools] Don't capture durations for disconnected subtrees when profiling#484

Closed
everettbu wants to merge 1 commit into
mainfrom
devtools/dont-capture-durations-for-disconnected-subtrees
Closed

[DevTools] Don't capture durations for disconnected subtrees when profiling#484
everettbu wants to merge 1 commit into
mainfrom
devtools/dont-capture-durations-for-disconnected-subtrees

Conversation

@everettbu

Copy link
Copy Markdown

Mirror of facebook/react#35718
Original author: hoxyq


After react/react#34089, when updating (possibly, mounting) inside disconnected subtree, we don't record this as an operation. This only happens during reconnect. The issue is that recordProfilingDurations() can be called, which diffs tree base duration and reports it to the Frontend:
https://github.com/facebook/react/blob/65db1000b944c8a07b5947c06b38eb8364dce4f2/packages/react-devtools-shared/src/backend/fiber/renderer.js#L4506-L4521

This operation can be recorded before the "Add" operation, and it will not be resolved properly on the Frontend side.

Before the fix:

commit tree › Suspense › should handle transitioning from fallback back to content during profiling

    Could not clone the node: commit tree does not contain fiber "5". This is a bug in React DevTools.

      162 |     const existingNode = nodes.get(id);
      163 |     if (existingNode == null) {
    > 164 |       throw new Error(
          |             ^
      165 |         `Could not clone the node: commit tree does not contain fiber "${id}". This is a bug in React DevTools.`,
      166 |       );
      167 |     }

      at getClonedNode (packages/react-devtools-shared/src/devtools/views/Profiler/CommitTreeBuilder.js:164:13)
      at updateTree (packages/react-devtools-shared/src/devtools/views/Profiler/CommitTreeBuilder.js:348:24)
      at getCommitTree (packages/react-devtools-shared/src/devtools/views/Profiler/CommitTreeBuilder.js:112:20)
      at ProfilingCache.getCommitTree (packages/react-devtools-shared/src/devtools/ProfilingCache.js:40:46)
      at Object.<anonymous> (packages/react-devtools-shared/src/__tests__/profilingCommitTreeBuilder-test.js:257:44)

@greptile-apps

greptile-apps Bot commented Feb 7, 2026

Copy link
Copy Markdown

Greptile Overview

Greptile Summary

This change prevents DevTools’ backend renderer from recording profiling duration ops while traversing a disconnected subtree. That avoids emitting TREE_OPERATION_UPDATE_TREE_BASE_DURATION updates for Fibers that have not yet been “Added” to the commit tree, which could previously break the Profiler CommitTreeBuilder during Suspense fallback→content transitions. A new regression test reproduces the sequence by profiling a Suspense boundary that suspends and later resolves, then builds commit trees for all captured commits to ensure no exceptions are thrown.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk.
  • Change is narrowly scoped: it gates profiling-duration operation emission on an existing isInDisconnectedSubtree flag, matching other disconnected-subtree behaviors (e.g., not measuring Suspense rects). Added test exercises the previously failing Suspense transition and validates commit tree building across all commits, which directly covers the reported crash.
  • No files require special attention

Important Files Changed

Filename Overview
packages/react-devtools-shared/src/backend/fiber/renderer.js Skip calling recordProfilingDurations while reconciling inside disconnected subtrees to avoid emitting out-of-order TREE_OPERATION_UPDATE_TREE_BASE_DURATION ops.
packages/react-devtools-shared/src/tests/profilingCommitTreeBuilder-test.js Add regression test that profiles a Suspense fallback→content transition and asserts commit trees can be built for every commit without throwing.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@everettbu

Copy link
Copy Markdown
Author

Upstream PR was closed or merged. Code is synced via branch mirror.

@everettbu everettbu closed this Feb 9, 2026
@everettbu
everettbu deleted the devtools/dont-capture-durations-for-disconnected-subtrees branch February 9, 2026 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants