[devtools]: Prevent false positive render detection in profiler (#33423, #19732)#111
Closed
everettbu wants to merge 2 commits into
Closed
[devtools]: Prevent false positive render detection in profiler (#33423, #19732)#111everettbu wants to merge 2 commits into
everettbu wants to merge 2 commits into
Conversation
- This commit addresses a bug in React DevTools where the profiler incorrectly reported user components as having re-rendered with the message "The parent component rendered," e
ven when they had not. This typically occurred for sibling components (like in the reported issue) nested under a (e.g., ) when the parent re-rendered.
- Problem: The function, which determines if a component has rendered, was being called for components whose Fiber object remained referentially identical (). While correctly
checks for changes in , , and , the issue stemmed from the fact that it was invoked at all for these unchanged components, leading to misleading "render" indications in the profiler a
nd highlight updates. The core problem was not the logic "within" , but rather the conditions under which it was "called".
- Solution: To resolve this, a conditional check has been added within the function, which is responsible for traversing and updating the Fiber tree. Before calling for user components (Function, Class, Memo, ForwardRef components), the system now verifies two key conditions:
1. : The Fiber object itself has not changed (i.e., it's the same instance).
2. is a or : The component's direct parent is a host element (like a ).
If both conditions are met, it indicates that the component has not genuinely re-rendered, and is explicitly set to . This prevents from being called unnecessarily and avoids the false positive reporting in the DevTools profiler and render highlighting. The same logic is applied when checking if has updated, ensuring consistency.
- This change significantly improves the accuracy of the React DevTools profiler and render highlighting, providing developers with more reliable information about component re-renders and bailouts.
Fixes #33423
Relates to #33434
…er filtered HostComponents
This commit addresses a bug in React DevTools where sibling user components were incorrectly reported as having re-rendered when they were nested under HostComponents (like <div>) that get filtered out by the DevTools component tree.
## Problem
When a user component (e.g., Count) triggers a re-render within a HostComponent
container, DevTools would incorrectly report sibling components (e.g., Greeting) as having re-rendered, even when their Fiber objects remained referentially
identical (prevFiber === nextFiber). This created misleading information in:
- Profiler data collection (false entries in commit data)
- Render highlighting (incorrect visual indicators)
- Inspector cache management (unnecessary invalidation)
## Root Cause
The issue occurred because didFiberRender() was being called for components
whose Fiber objects hadn't actually changed, but were children of HostComponents
that were being processed during reconciliation. Since HostComponents are
filtered out by default in DevTools, the relationship between unchanged sibling
components wasn't being properly recognized. │
## Solution
Instead of modifying the didFiberRender() function itself, this fix prevents
the function from being called when we can determine that a component hasn't
actually re-rendered. The key insight is that if:
- prevFiber === nextFiber (same Fiber object reference)
- nextFiber.return is a HostComponent or HostSingleton
Then the component didn't actually re-render and didFiberRender() shouldn't be invoked.
Greptile OverviewGreptile SummaryCompletes the fix for false positive render detection in React DevTools by adding the same conditional check to profiler data collection that was previously applied to render highlighting and inspector cache management.
Confidence Score: 5/5
Important Files ChangedFile Analysis
|
Author
|
Upstream PR was closed or merged. Code is synced via branch mirror. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mirror of facebook/react#33964
Original author: developerjhp
Summary
Fixes a bug in React DevTools where the profiler incorrectly reported sibling components as re-rendered when they were nested under HostComponents (like
<div>) that get filtered out by DevTools. This affected profiler data collection, render highlighting, and inspector cache management.Background
React DevTools filters out DOM elements (HostComponents) by default to focus on user components. However, this filtering created a blind spot where sibling components under the same HostComponent parent would be incorrectly reported as re-rendered even when their Fiber objects remained identical.
This is a follow-up to #33434
Previous Attempt & Learning
#33434 helped identify that the issue wasn't with
didFiberRenderlogic itself, but with when it was being called. The filtering behavior provided the key insight that components with identical Fiber objects shouldn't trigger renderdetection when their parent HostComponents are filtered.
Example scenario:
Root Cause
The issue occurred because didFiberRender was being called for components whose Fiber objects remained referentially identical (prevFiber === nextFiber) but were nested under HostComponents. When the parent HostComponent processed its children during reconciliation, DevTools would check all child components without recognizing that some hadn't actually re-rendered.
Key insight
If prevFiber === nextFiber and the parent is a filtered HostComponent, then didFiberRender shouldn't be called at all - not because the function is wrong, but because the component genuinely hasn't re-rendered.
Solution
Instead of modifying didFiberRender logic, this fix prevents the function from being called when we can objectively determine a component hasn't re-rendered. The fix adds conditional checks in three critical locations:
Implementation Details
The fix uses objective criteria to detect when didFiberRender shouldn't be called:
This approach:
Related Issues
Fixes #33423, #19732