Skip to content

[DevTools] Fix commit index reset when switching profiler roots#450

Closed
everettbu wants to merge 1 commit into
mainfrom
fix-profiler-commit-index-on-root-switch
Closed

[DevTools] Fix commit index reset when switching profiler roots#450
everettbu wants to merge 1 commit into
mainfrom
fix-profiler-commit-index-on-root-switch

Conversation

@everettbu

Copy link
Copy Markdown

Mirror of facebook/react#35672
Original author: hoxyq


Fixes react/react#31463, react/react#30114.

When switching between roots in the profiler flamegraph, the commit index was preserved from the previous root. This caused an error "Invalid commit X. There are only Y commits." when the new root had fewer commits than the selected index.

This fix resets the commit index to 0 (or null if no commits) when the commitData changes, which happens when switching roots.

@greptile-apps

greptile-apps Bot commented Feb 2, 2026

Copy link
Copy Markdown

Greptile Overview

Greptile Summary

Fixed a bug where switching between profiler roots with different commit counts caused an "Invalid commit X" error. The fix adds a check in useCommitFilteringAndNavigation that resets the commit index to 0 (or null if no commits) whenever the commitData changes, which happens when switching roots.

  • Implemented commit index reset logic using the React state pattern to detect commitData changes
  • Added a comprehensive test case that verifies the behavior with two roots having different commit counts (5 vs 2)
  • The test confirms that navigating to commit index 3 in the first root, then switching to the second root (which only has 2 commits) properly resets to index 0

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix is well-targeted and uses an established React pattern for detecting prop changes. The comprehensive test case covers the exact bug scenario with multiple roots and different commit counts
  • No files require special attention

Important Files Changed

Filename Overview
packages/react-devtools-shared/src/devtools/views/Profiler/useCommitFilteringAndNavigation.js Added commit index reset logic when commitData changes to prevent invalid index errors when switching between roots
packages/react-devtools-shared/src/tests/profilerContext-test.js Added comprehensive test case to verify commit index resets correctly when switching between profiler roots with different commit counts

@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

When switching between roots in the profiler flamegraph, the commit
index was preserved from the previous root. This caused an error
"Invalid commit X. There are only Y commits." when the new root had
fewer commits than the selected index.

This fix resets the commit index to 0 (or null if no commits) when the
commitData changes, which happens when switching roots.
@everettbu
everettbu force-pushed the fix-profiler-commit-index-on-root-switch branch from 394243e to d8dd1d8 Compare February 2, 2026 23:11

@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 3, 2026
@everettbu
everettbu deleted the fix-profiler-commit-index-on-root-switch branch February 3, 2026 13:40
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.

[DevTools Bug] getCommitTree(): Invalid commit "7" for root "1". There are only "7" commits.

2 participants