-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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 fiber summary tooltip to devtools profiling #18048
Merged
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
be77110
Add tooltip component
M-Izadmehr 9b5c730
Separate logic of ProfilerWhatChanged to a component
M-Izadmehr 1cfcd33
Add hovered Fiber info tooltip component
M-Izadmehr edd6e8e
Add flame graph chart tooltip
M-Izadmehr 255e741
Add commit ranked list tooltip
M-Izadmehr 8247667
Fix flow issues
M-Izadmehr 4995ac9
Minor improvement in filter
M-Izadmehr be5f04e
Fix flickering issue
M-Izadmehr e1e114c
Resolved issues on useCallbacks and mouse event listeners
M-Izadmehr 0bd6e07
Fix lints
M-Izadmehr 20caae7
Remove unnecessary useCallback
M-Izadmehr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
packages/react-devtools-shared/src/devtools/views/Components/ProfilerWhatChanged.css
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,30 @@ | ||
.Component { | ||
margin-bottom: 1rem; | ||
} | ||
|
||
.Item { | ||
margin-top: 0.25rem; | ||
} | ||
|
||
.Key { | ||
font-family: var(--font-family-monospace); | ||
font-size: var(--font-size-monospace-small); | ||
line-height: 1; | ||
} | ||
|
||
.Key:first-of-type::before { | ||
content: ' ('; | ||
} | ||
|
||
.Key::after { | ||
content: ', '; | ||
} | ||
|
||
.Key:last-of-type::after { | ||
content: ')'; | ||
} | ||
|
||
.Label { | ||
font-weight: bold; | ||
margin-bottom: 0.5rem; | ||
} |
138 changes: 138 additions & 0 deletions
138
packages/react-devtools-shared/src/devtools/views/Components/ProfilerWhatChanged.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,138 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import React, {useContext} from 'react'; | ||
import {ProfilerContext} from '../Profiler/ProfilerContext'; | ||
import {StoreContext} from '../context'; | ||
|
||
import styles from './ProfilerWhatChanged.css'; | ||
|
||
type ProfilerWhatChangedProps = {| | ||
fiberID: number, | ||
|}; | ||
|
||
export default function ProfilerWhatChanged({ | ||
fiberID, | ||
}: ProfilerWhatChangedProps) { | ||
const {profilerStore} = useContext(StoreContext); | ||
const {rootID, selectedCommitIndex} = useContext(ProfilerContext); | ||
|
||
// TRICKY | ||
// Handle edge case where no commit is selected because of a min-duration filter update. | ||
// If the commit index is null, suspending for data below would throw an error. | ||
// TODO (ProfilerContext) This check should not be necessary. | ||
if (selectedCommitIndex === null) { | ||
return null; | ||
} | ||
|
||
const {changeDescriptions} = profilerStore.getCommitData( | ||
((rootID: any): number), | ||
selectedCommitIndex, | ||
); | ||
|
||
if (changeDescriptions === null) { | ||
return null; | ||
} | ||
|
||
const changeDescription = changeDescriptions.get(fiberID); | ||
if (changeDescription == null) { | ||
return null; | ||
} | ||
|
||
if (changeDescription.isFirstMount) { | ||
return ( | ||
<div className={styles.Component}> | ||
<label className={styles.Label}>Why did this render?</label> | ||
<div className={styles.Item}> | ||
This is the first time the component rendered. | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
const changes = []; | ||
|
||
if (changeDescription.context === true) { | ||
changes.push( | ||
<div key="context" className={styles.Item}> | ||
• Context changed | ||
</div>, | ||
); | ||
} else if ( | ||
typeof changeDescription.context === 'object' && | ||
changeDescription.context !== null && | ||
changeDescription.context.length !== 0 | ||
) { | ||
changes.push( | ||
<div key="context" className={styles.Item}> | ||
• Context changed: | ||
{changeDescription.context.map(key => ( | ||
<span key={key} className={styles.Key}> | ||
{key} | ||
</span> | ||
))} | ||
</div>, | ||
); | ||
} | ||
|
||
if (changeDescription.didHooksChange) { | ||
changes.push( | ||
<div key="hooks" className={styles.Item}> | ||
• Hooks changed | ||
</div>, | ||
); | ||
} | ||
|
||
if ( | ||
changeDescription.props !== null && | ||
changeDescription.props.length !== 0 | ||
) { | ||
changes.push( | ||
<div key="props" className={styles.Item}> | ||
• Props changed: | ||
{changeDescription.props.map(key => ( | ||
<span key={key} className={styles.Key}> | ||
{key} | ||
</span> | ||
))} | ||
</div>, | ||
); | ||
} | ||
|
||
if ( | ||
changeDescription.state !== null && | ||
changeDescription.state.length !== 0 | ||
) { | ||
changes.push( | ||
<div key="state" className={styles.Item}> | ||
• State changed: | ||
{changeDescription.state.map(key => ( | ||
<span key={key} className={styles.Key}> | ||
{key} | ||
</span> | ||
))} | ||
</div>, | ||
); | ||
} | ||
|
||
if (changes.length === 0) { | ||
changes.push( | ||
<div key="nothing" className={styles.Item}> | ||
The parent component rendered. | ||
</div>, | ||
); | ||
} | ||
|
||
return ( | ||
<div className={styles.Component}> | ||
<label className={styles.Label}>Why did this render?</label> | ||
{changes} | ||
</div> | ||
); | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/react-devtools-shared/src/devtools/views/Components/Tooltip.css
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,19 @@ | ||
.Tooltip { | ||
position: absolute; | ||
pointer-events: none; | ||
border: none; | ||
border-radius: 0.25rem; | ||
padding: 0.25rem 0.5rem; | ||
font-family: var(--font-family-sans); | ||
font-size: 12px; | ||
background-color: var(--color-tooltip-background); | ||
color: var(--color-tooltip-text); | ||
|
||
/* Make sure this is above the DevTools, which are above the Overlay */ | ||
z-index: 10000002; | ||
} | ||
|
||
.Container { | ||
width: -moz-max-content; | ||
width: -webkit-max-content; | ||
} |
51 changes: 51 additions & 0 deletions
51
packages/react-devtools-shared/src/devtools/views/Components/Tooltip.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,51 @@ | ||
/** @flow */ | ||
|
||
import React, {useCallback, useRef, useState} from 'react'; | ||
import {useSmartTooltip} from '../hooks'; | ||
|
||
import styles from './Tooltip.css'; | ||
|
||
const initialTooltipState = {height: 0, mouseX: 0, mouseY: 0, width: 0}; | ||
|
||
export default function Tooltip({children, label}: any) { | ||
const containerRef = useRef(null); | ||
const [tooltipState, setTooltipState] = useState(initialTooltipState); | ||
const tooltipRef = useSmartTooltip(tooltipState); | ||
|
||
const onMouseMove = useCallback( | ||
M-Izadmehr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(event: SyntheticMouseEvent<*>) => { | ||
setTooltipState(getTooltipPosition(containerRef.current, event)); | ||
}, | ||
[setTooltipState], | ||
); | ||
|
||
return ( | ||
<div | ||
className={styles.Container} | ||
onMouseMove={label !== null ? onMouseMove : undefined} | ||
ref={containerRef}> | ||
{label !== null && ( | ||
<div ref={tooltipRef} className={styles.Tooltip}> | ||
{label} | ||
</div> | ||
)} | ||
{children} | ||
</div> | ||
); | ||
} | ||
|
||
function getTooltipPosition( | ||
relativeContainer, | ||
mouseEvent: SyntheticMouseEvent<*>, | ||
) { | ||
if (relativeContainer !== null) { | ||
const {height, top, width} = relativeContainer.getBoundingClientRect(); | ||
|
||
const mouseX = mouseEvent.clientX; | ||
const mouseY = mouseEvent.clientY - top; | ||
|
||
return {height, mouseX, mouseY, width}; | ||
} else { | ||
return initialTooltipState; | ||
} | ||
} |
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
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.
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.
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.
Tiny nit, and I'm happy to do this post-merge- BUT! The new
Tooltip
andWhatChanged
components are only used by views in the "Profiler" tab, so they should be inviews/Profiler
rather thanviews/Components
(which is where views for the "Components" tab live). I would be happy to sort this out with agit mv
after the PR merge though!