-
Notifications
You must be signed in to change notification settings - Fork 47.5k
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
Fix Profiler root change error #18880
Changes from 2 commits
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 |
---|---|---|
|
@@ -22,7 +22,7 @@ import type {ProfilingDataFrontend} from './types'; | |
export type TabID = 'flame-chart' | 'ranked-chart' | 'interactions'; | ||
|
||
export type Context = {| | ||
// Which tab is selexted in the Profiler UI? | ||
// Which tab is selected in the Profiler UI? | ||
selectedTabID: TabID, | ||
selectTab(id: TabID): void, | ||
|
||
|
@@ -43,7 +43,7 @@ export type Context = {| | |
// 1. The selected root in the Components tree (if it has any profiling data) or | ||
// 2. The first root in the list with profiling data. | ||
rootID: number | null, | ||
setRootID: (id: number) => void, | ||
setRootIDcleanFiber: (id: number) => void, | ||
|
||
// Controls whether commits are filtered by duration. | ||
// This value is controlled by a filter toggle UI in the Profiler toolbar. | ||
|
@@ -129,6 +129,38 @@ function ProfilerContextController({children}: Props) { | |
setPrevProfilingData, | ||
] = useState<ProfilingDataFrontend | null>(null); | ||
const [rootID, setRootID] = useState<number | null>(null); | ||
const [selectedFiberID, selectFiberID] = useState<number | null>(null); | ||
const [selectedFiberName, selectFiberName] = useState<string | null>(null); | ||
|
||
const selectFiber = useCallback( | ||
(id: number | null, name: string | null) => { | ||
selectFiberID(id); | ||
selectFiberName(name); | ||
|
||
// Sync selection to the Components tab for convenience. | ||
if (id !== null) { | ||
const element = store.getElementByID(id); | ||
|
||
// Keep in mind that profiling data may be from a previous session. | ||
// In that case, IDs may match up arbitrarily; to be safe, compare both ID and display name. | ||
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. Ah, right. So this seems to come up in a few places. I know this check was copied from pre-existing code, but looking at it again- the heuristic is flawed. ID and name might still happen to match for imported data. We should check something on the data itself to show that it was imported or not, and just skip looking in the store for such imported elements. We could add a new field to the 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. Yeah, it could be interesting to do. Is all of the task description in this comment? 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. Not sure I understand? I'm just thinking we might add a flag to the 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. Just to be clear, this doesn't need to be done- at least not as part of this PR. I could do it as a follow up (or you could if you're interested). 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. I'll try to do it in the next few days, thanks! 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. |
||
if (element !== null && element.displayName === name) { | ||
dispatch({ | ||
type: 'SELECT_ELEMENT_BY_ID', | ||
payload: id, | ||
}); | ||
} | ||
} | ||
}, | ||
[dispatch, selectFiberID, selectFiberName, store], | ||
); | ||
|
||
const setRootIDcleanFiber = useCallback( | ||
(id: number | null) => { | ||
selectFiber(null, null); | ||
setRootID(id); | ||
}, | ||
[setRootID, selectFiber], | ||
); | ||
|
||
if (prevProfilingData !== profilingData) { | ||
batchedUpdates(() => { | ||
|
@@ -150,9 +182,9 @@ function ProfilerContextController({children}: Props) { | |
selectedElementRootID !== null && | ||
dataForRoots.has(selectedElementRootID) | ||
) { | ||
setRootID(selectedElementRootID); | ||
setRootIDcleanFiber(selectedElementRootID); | ||
} else { | ||
setRootID(firstRootID); | ||
setRootIDcleanFiber(firstRootID); | ||
} | ||
} | ||
} | ||
|
@@ -180,34 +212,10 @@ function ProfilerContextController({children}: Props) { | |
null, | ||
); | ||
const [selectedTabID, selectTab] = useState<TabID>('flame-chart'); | ||
const [selectedFiberID, selectFiberID] = useState<number | null>(null); | ||
const [selectedFiberName, selectFiberName] = useState<string | null>(null); | ||
const [selectedInteractionID, selectInteraction] = useState<number | null>( | ||
null, | ||
); | ||
|
||
const selectFiber = useCallback( | ||
(id: number | null, name: string | null) => { | ||
selectFiberID(id); | ||
selectFiberName(name); | ||
|
||
// Sync selection to the Components tab for convenience. | ||
if (id !== null) { | ||
const element = store.getElementByID(id); | ||
|
||
// Keep in mind that profiling data may be from a previous session. | ||
// In that case, IDs may match up arbitrarily; to be safe, compare both ID and display name. | ||
if (element !== null && element.displayName === name) { | ||
dispatch({ | ||
type: 'SELECT_ELEMENT_BY_ID', | ||
payload: id, | ||
}); | ||
} | ||
} | ||
}, | ||
[dispatch, selectFiberID, selectFiberName, store], | ||
); | ||
|
||
if (isProfiling) { | ||
batchedUpdates(() => { | ||
if (selectedCommitIndex !== null) { | ||
|
@@ -237,7 +245,7 @@ function ProfilerContextController({children}: Props) { | |
supportsProfiling, | ||
|
||
rootID, | ||
setRootID, | ||
setRootIDcleanFiber, | ||
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. In other words, |
||
|
||
isCommitFilterEnabled, | ||
setIsCommitFilterEnabled, | ||
|
@@ -267,7 +275,7 @@ function ProfilerContextController({children}: Props) { | |
supportsProfiling, | ||
|
||
rootID, | ||
setRootID, | ||
setRootIDcleanFiber, | ||
|
||
isCommitFilterEnabled, | ||
setIsCommitFilterEnabled, | ||
|
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.
I think
setRootIDcleanFiber
is kind of an awkward name. Prefer to just leave the name we pass down through the context assetRootID
(and change the implementation to also clear the fiber ID like you did)