forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DevTools] Show component names while highlighting renders (facebook#…
…31577) ## Summary This PR improves the Trace Updates feature by letting developers see component names directly on the update overlay. Before this change, the overlay only highlighted updated regions, leaving it unclear which components were involved. With this update, you can now match visual updates to their corresponding components, making it much easier to debug rendering performance. ### New Feature: Show component names while highlighting When the new **"Show component names while highlighting"** setting is enabled, the update overlay display the names of affected components above the rectangles, along with the update count. This gives immediate context about what’s rendering and why. The preference is stored in local storage and synced with the backend, so it’s remembered across sessions. ### Improvements to Drawing Logic The drawing logic has been updated to make the overlay sharper and easier to read. Overlay now respect device pixel ratios, so they look great on high-DPI screens. Outlines have also been made crisper, which makes it easier to spot exactly where updates are happening. > [!NOTE] > **Grouping Logic and Limitations** > Updates are grouped by their screen position `(left, top coordinates)` to combine overlapping or nearby regions into a single group. Groups are sorted by the highest update count within each group, making the most frequently updated components stand out. > Overlapping labels may still occur when multiple updates involve components that overlap but are not in the exact same position. This is intentional, as the logic aims to maintain a straightforward mapping between update regions and component names without introducing unnecessary complexity. ### Testing This PR also adds tests for the new `groupAndSortNodes` utility, which handles the logic for grouping and sorting updates. The tests ensure the behavior is reliable across different scenarios. ## Before & After https://github.com/user-attachments/assets/6ea0fe3e-9354-44fa-95f3-9a867554f74c https://github.com/user-attachments/assets/32af4d98-92a5-47dd-a732-f05c2293e41b --------- Co-authored-by: Ruslan Lesiutin <[email protected]>
- Loading branch information
Showing
10 changed files
with
505 additions
and
40 deletions.
There are no files selected for viewing
269 changes: 269 additions & 0 deletions
269
packages/react-devtools-shared/src/__tests__/traceUpdates-test.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,269 @@ | ||
import {groupAndSortNodes} from 'react-devtools-shared/src/backend/views/TraceUpdates/canvas'; | ||
|
||
describe('Trace updates group and sort nodes', () => { | ||
test('should group nodes by position without changing order within group', () => { | ||
const nodeToData = new Map([ | ||
[ | ||
{id: 1}, | ||
{ | ||
rect: {left: 0, top: 0, width: 100, height: 100}, | ||
color: '#80b393', | ||
displayName: 'Node1', | ||
count: 3, | ||
}, | ||
], | ||
[ | ||
{id: 2}, | ||
{ | ||
rect: {left: 0, top: 0, width: 100, height: 100}, | ||
color: '#63b19e', | ||
displayName: 'Node2', | ||
count: 2, | ||
}, | ||
], | ||
]); | ||
|
||
const result = groupAndSortNodes(nodeToData); | ||
|
||
expect(result).toEqual([ | ||
[ | ||
{ | ||
rect: {left: 0, top: 0, width: 100, height: 100}, | ||
color: '#80b393', | ||
displayName: 'Node1', | ||
count: 3, | ||
}, | ||
{ | ||
rect: {left: 0, top: 0, width: 100, height: 100}, | ||
color: '#63b19e', | ||
displayName: 'Node2', | ||
count: 2, | ||
}, | ||
], | ||
]); | ||
}); | ||
|
||
test('should sort groups by lowest count in each group', () => { | ||
const nodeToData = new Map([ | ||
[ | ||
{id: 1}, | ||
{ | ||
rect: {left: 0, top: 0, width: 100, height: 100}, | ||
color: '#97b488', | ||
displayName: 'Group1', | ||
count: 4, | ||
}, | ||
], | ||
[ | ||
{id: 2}, | ||
{ | ||
rect: {left: 100, top: 0, width: 100, height: 100}, | ||
color: '#37afa9', | ||
displayName: 'Group2', | ||
count: 1, | ||
}, | ||
], | ||
[ | ||
{id: 3}, | ||
{ | ||
rect: {left: 200, top: 0, width: 100, height: 100}, | ||
color: '#63b19e', | ||
displayName: 'Group3', | ||
count: 2, | ||
}, | ||
], | ||
]); | ||
|
||
const result = groupAndSortNodes(nodeToData); | ||
|
||
expect(result).toEqual([ | ||
[ | ||
{ | ||
rect: {left: 100, top: 0, width: 100, height: 100}, | ||
color: '#37afa9', | ||
displayName: 'Group2', | ||
count: 1, | ||
}, | ||
], | ||
[ | ||
{ | ||
rect: {left: 200, top: 0, width: 100, height: 100}, | ||
color: '#63b19e', | ||
displayName: 'Group3', | ||
count: 2, | ||
}, | ||
], | ||
[ | ||
{ | ||
rect: {left: 0, top: 0, width: 100, height: 100}, | ||
color: '#97b488', | ||
displayName: 'Group1', | ||
count: 4, | ||
}, | ||
], | ||
]); | ||
}); | ||
|
||
test('should maintain order within groups while sorting groups by lowest count', () => { | ||
const nodeToData = new Map([ | ||
[ | ||
{id: 1}, | ||
{ | ||
rect: {left: 0, top: 0, width: 50, height: 50}, | ||
color: '#97b488', | ||
displayName: 'Pos1Node1', | ||
count: 4, | ||
}, | ||
], | ||
[ | ||
{id: 2}, | ||
{ | ||
rect: {left: 0, top: 0, width: 60, height: 60}, | ||
color: '#63b19e', | ||
displayName: 'Pos1Node2', | ||
count: 2, | ||
}, | ||
], | ||
[ | ||
{id: 3}, | ||
{ | ||
rect: {left: 100, top: 0, width: 70, height: 70}, | ||
color: '#80b393', | ||
displayName: 'Pos2Node1', | ||
count: 3, | ||
}, | ||
], | ||
[ | ||
{id: 4}, | ||
{ | ||
rect: {left: 100, top: 0, width: 80, height: 80}, | ||
color: '#37afa9', | ||
displayName: 'Pos2Node2', | ||
count: 1, | ||
}, | ||
], | ||
]); | ||
|
||
const result = groupAndSortNodes(nodeToData); | ||
|
||
expect(result).toEqual([ | ||
[ | ||
{ | ||
rect: {left: 100, top: 0, width: 70, height: 70}, | ||
color: '#80b393', | ||
displayName: 'Pos2Node1', | ||
count: 3, | ||
}, | ||
{ | ||
rect: {left: 100, top: 0, width: 80, height: 80}, | ||
color: '#37afa9', | ||
displayName: 'Pos2Node2', | ||
count: 1, | ||
}, | ||
], | ||
[ | ||
{ | ||
rect: {left: 0, top: 0, width: 50, height: 50}, | ||
color: '#97b488', | ||
displayName: 'Pos1Node1', | ||
count: 4, | ||
}, | ||
{ | ||
rect: {left: 0, top: 0, width: 60, height: 60}, | ||
color: '#63b19e', | ||
displayName: 'Pos1Node2', | ||
count: 2, | ||
}, | ||
], | ||
]); | ||
}); | ||
|
||
test('should handle multiple groups with same minimum count', () => { | ||
const nodeToData = new Map([ | ||
[ | ||
{id: 1}, | ||
{ | ||
rect: {left: 0, top: 0, width: 100, height: 100}, | ||
color: '#37afa9', | ||
displayName: 'Group1Node1', | ||
count: 1, | ||
}, | ||
], | ||
[ | ||
{id: 2}, | ||
{ | ||
rect: {left: 100, top: 0, width: 100, height: 100}, | ||
color: '#37afa9', | ||
displayName: 'Group2Node1', | ||
count: 1, | ||
}, | ||
], | ||
]); | ||
|
||
const result = groupAndSortNodes(nodeToData); | ||
|
||
expect(result).toEqual([ | ||
[ | ||
{ | ||
rect: {left: 0, top: 0, width: 100, height: 100}, | ||
color: '#37afa9', | ||
displayName: 'Group1Node1', | ||
count: 1, | ||
}, | ||
], | ||
[ | ||
{ | ||
rect: {left: 100, top: 0, width: 100, height: 100}, | ||
color: '#37afa9', | ||
displayName: 'Group2Node1', | ||
count: 1, | ||
}, | ||
], | ||
]); | ||
}); | ||
|
||
test('should filter out nodes without rect property', () => { | ||
const nodeToData = new Map([ | ||
[ | ||
{id: 1}, | ||
{ | ||
rect: null, | ||
color: '#37afa9', | ||
displayName: 'NoRectNode', | ||
count: 1, | ||
}, | ||
], | ||
[ | ||
{id: 2}, | ||
{ | ||
rect: undefined, | ||
color: '#63b19e', | ||
displayName: 'UndefinedRectNode', | ||
count: 2, | ||
}, | ||
], | ||
[ | ||
{id: 3}, | ||
{ | ||
rect: {left: 0, top: 0, width: 100, height: 100}, | ||
color: '#80b393', | ||
displayName: 'ValidNode', | ||
count: 3, | ||
}, | ||
], | ||
]); | ||
|
||
const result = groupAndSortNodes(nodeToData); | ||
|
||
expect(result).toEqual([ | ||
[ | ||
{ | ||
rect: {left: 0, top: 0, width: 100, height: 100}, | ||
color: '#80b393', | ||
displayName: 'ValidNode', | ||
count: 3, | ||
}, | ||
], | ||
]); | ||
}); | ||
}); |
This file contains 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
Oops, something went wrong.