-
Notifications
You must be signed in to change notification settings - Fork 48.4k
Add Component Highlighting to Profiler DevTools #17934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
fe43dc8
0deb555
53a84ce
d539137
5f66d47
c6bcac3
ed6fe06
c73bd21
49ea156
ab5b537
0fd63c0
2958df7
0a24f63
1c1c2b6
ce9b3a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ import {ProfilerContext} from './ProfilerContext'; | |
import NoCommitData from './NoCommitData'; | ||
import CommitFlamegraphListItem from './CommitFlamegraphListItem'; | ||
import {scale} from './utils'; | ||
import {StoreContext} from '../context'; | ||
import {BridgeContext, StoreContext} from '../context'; | ||
import {SettingsContext} from '../Settings/SettingsContext'; | ||
|
||
import styles from './CommitFlamegraph.css'; | ||
|
@@ -24,6 +24,7 @@ import type {CommitTree} from './types'; | |
|
||
export type ItemData = {| | ||
chartData: ChartData, | ||
onElementMouseEnter: (id: number) => void, | ||
scaleX: (value: number, fallbackValue: number) => number, | ||
selectedChartNode: ChartNode | null, | ||
selectedChartNodeIndex: number, | ||
|
@@ -93,6 +94,8 @@ type Props = {| | |
function CommitFlamegraph({chartData, commitTree, height, width}: Props) { | ||
const {lineHeight} = useContext(SettingsContext); | ||
const {selectFiber, selectedFiberID} = useContext(ProfilerContext); | ||
const store = useContext(StoreContext); | ||
const bridge = useContext(BridgeContext); | ||
|
||
const selectedChartNodeIndex = useMemo<number>(() => { | ||
if (selectedFiberID === null) { | ||
|
@@ -115,9 +118,36 @@ function CommitFlamegraph({chartData, commitTree, height, width}: Props) { | |
return null; | ||
}, [chartData, selectedFiberID, selectedChartNodeIndex]); | ||
|
||
const highlightNativeElement = useCallback( | ||
(id: number) => { | ||
const element = store.getElementByID(id); | ||
const rendererID = store.getRendererIDForElement(id); | ||
if (element !== null && rendererID !== null) { | ||
bridge.send('highlightNativeElement', { | ||
displayName: element.displayName, | ||
hideAfterTimeout: false, | ||
id, | ||
openNativeElementsPanel: false, | ||
rendererID, | ||
scrollIntoView: false, | ||
}); | ||
} | ||
}, | ||
[store, bridge], | ||
); | ||
|
||
// Highlight last hovered element. | ||
const handleElementMouseEnter = useCallback( | ||
id => { | ||
highlightNativeElement(id); | ||
}, | ||
[highlightNativeElement], | ||
); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This section is also repeated in Maybe better to create a separate hook file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the comment, Yeah I absolutely agree, I will try to use a hook for the highlighting functionality:) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, now I extracted the highlighting logic to the hooks file, and created a hook called
|
||
const itemData = useMemo<ItemData>( | ||
() => ({ | ||
chartData, | ||
onElementMouseEnter: handleElementMouseEnter, | ||
scaleX: scale( | ||
0, | ||
selectedChartNode !== null | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@M-Izadmehr, can you please explain why you wrap in another
useCallback
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done:)
I removed the useless
useCallback
.