-
Notifications
You must be signed in to change notification settings - Fork 47.4k
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
Add Component Highlighting to Profiler DevTools #17934
Changes from all 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 |
---|---|---|
|
@@ -16,6 +16,7 @@ import NoCommitData from './NoCommitData'; | |
import CommitFlamegraphListItem from './CommitFlamegraphListItem'; | ||
import HoveredFiberInfo from './HoveredFiberInfo'; | ||
import {scale} from './utils'; | ||
import {useNativeElementHighlighter} from '../hooks'; | ||
import {StoreContext} from '../context'; | ||
import {SettingsContext} from '../Settings/SettingsContext'; | ||
import Tooltip from './Tooltip'; | ||
|
@@ -28,7 +29,9 @@ import type {CommitTree} from './types'; | |
|
||
export type ItemData = {| | ||
chartData: ChartData, | ||
hoverFiber: (fiberData: TooltipFiberData | null) => void, | ||
isHovered: boolean, | ||
onElementMouseEnter: (fiberData: TooltipFiberData) => void, | ||
onElementMouseLeave: () => void, | ||
scaleX: (value: number, fallbackValue: number) => number, | ||
selectedChartNode: ChartNode | null, | ||
selectedChartNodeIndex: number, | ||
|
@@ -96,9 +99,13 @@ type Props = {| | |
|}; | ||
|
||
function CommitFlamegraph({chartData, commitTree, height, width}: Props) { | ||
const [hoveredFiberData, hoverFiber] = useState<number | null>(null); | ||
const [hoveredFiberData, setHoveredFiberData] = useState<number | null>(null); | ||
const {lineHeight} = useContext(SettingsContext); | ||
const {selectFiber, selectedFiberID} = useContext(ProfilerContext); | ||
const { | ||
highlightNativeElement, | ||
clearNativeElementHighlight, | ||
} = useNativeElementHighlighter(); | ||
|
||
const selectedChartNodeIndex = useMemo<number>(() => { | ||
if (selectedFiberID === null) { | ||
|
@@ -121,10 +128,22 @@ function CommitFlamegraph({chartData, commitTree, height, width}: Props) { | |
return null; | ||
}, [chartData, selectedFiberID, selectedChartNodeIndex]); | ||
|
||
const handleElementMouseEnter = ({id, name}) => { | ||
highlightNativeElement(id); // Highlight last hovered element. | ||
setHoveredFiberData({id, name}); // Set hovered fiber data for tooltip | ||
}; | ||
|
||
const handleElementMouseLeave = () => { | ||
bvaughn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
clearNativeElementHighlight(); // clear highlighting of element on mouse leave | ||
setHoveredFiberData(null); // clear hovered fiber data for tooltip | ||
}; | ||
|
||
const itemData = useMemo<ItemData>( | ||
() => ({ | ||
chartData, | ||
hoverFiber, | ||
isHovered: hoveredFiberData && hoveredFiberData.id, | ||
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. Why is this check not just |
||
onElementMouseEnter: handleElementMouseEnter, | ||
onElementMouseLeave: handleElementMouseLeave, | ||
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 looks wrong. Neither I wonder why our lint rule isn't complaining about this. 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. Good catch |
||
scaleX: scale( | ||
0, | ||
selectedChartNode !== null | ||
|
@@ -140,7 +159,7 @@ function CommitFlamegraph({chartData, commitTree, height, width}: Props) { | |
}), | ||
[ | ||
chartData, | ||
hoverFiber, | ||
setHoveredFiberData, | ||
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 looks wrong. The dependencies array has I wonder why our lint rule isn't complaining about this. |
||
selectedChartNode, | ||
selectedChartNodeIndex, | ||
selectFiber, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ import HoveredFiberInfo from './HoveredFiberInfo'; | |
import {scale} from './utils'; | ||
import {StoreContext} from '../context'; | ||
import {SettingsContext} from '../Settings/SettingsContext'; | ||
import {useNativeElementHighlighter} from '../hooks'; | ||
import Tooltip from './Tooltip'; | ||
|
||
import styles from './CommitRanked.css'; | ||
|
@@ -28,7 +29,9 @@ import type {CommitTree} from './types'; | |
|
||
export type ItemData = {| | ||
chartData: ChartData, | ||
hoverFiber: (fiberData: TooltipFiberData | null) => void, | ||
isHovered: boolean, | ||
onElementMouseEnter: (fiberData: TooltipFiberData) => void, | ||
onElementMouseLeave: () => void, | ||
scaleX: (value: number, fallbackValue: number) => number, | ||
selectedFiberID: number | null, | ||
selectedFiberIndex: number, | ||
|
@@ -94,19 +97,35 @@ type Props = {| | |
|}; | ||
|
||
function CommitRanked({chartData, commitTree, height, width}: Props) { | ||
const [hoveredFiberData, hoverFiber] = useState<number | null>(null); | ||
const [hoveredFiberData, setHoveredFiberData] = useState<number | null>(null); | ||
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. Same comment as above wrt hook state type. |
||
const {lineHeight} = useContext(SettingsContext); | ||
const {selectedFiberID, selectFiber} = useContext(ProfilerContext); | ||
const { | ||
highlightNativeElement, | ||
clearNativeElementHighlight, | ||
} = useNativeElementHighlighter(); | ||
|
||
const selectedFiberIndex = useMemo( | ||
() => getNodeIndex(chartData, selectedFiberID), | ||
[chartData, selectedFiberID], | ||
); | ||
|
||
const handleElementMouseEnter = ({id, name}) => { | ||
highlightNativeElement(id); // Highlight last hovered element. | ||
setHoveredFiberData({id, name}); // Set hovered fiber data for tooltip | ||
}; | ||
|
||
const handleElementMouseLeave = () => { | ||
bvaughn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
clearNativeElementHighlight(); // clear highlighting of element on mouse leave | ||
setHoveredFiberData(null); // clear hovered fiber data for tooltip | ||
}; | ||
|
||
const itemData = useMemo<ItemData>( | ||
() => ({ | ||
chartData, | ||
hoverFiber, | ||
isHovered: hoveredFiberData && hoveredFiberData.id, | ||
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. Same comment as above wrt |
||
onElementMouseEnter: handleElementMouseEnter, | ||
onElementMouseLeave: handleElementMouseLeave, | ||
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. Same comment as above wrt missing dependencies. |
||
scaleX: scale(0, chartData.nodes[selectedFiberIndex].value, 0, width), | ||
selectedFiberID, | ||
selectedFiberIndex, | ||
|
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.
This Flow type looks wrong. (Looks like it's been wrong for a while though FWIW- which is a bit concerning.)
We aren't storing a
number
in this state, but an object withid
andname
props (TooltipFiberData
).