Skip to content
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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The 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 ProfilingDataFrontend type to track this. Interested in tackling this? (Totally fine if you aren't, I could do it.)

Copy link
Contributor Author

@bl00mber bl00mber May 12, 2020

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

Choose a reason for hiding this comment

The 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 ProfilingDataFrontend that specifies whether it was imported (from a previous session) then use that flag to determine if we should disable certain features (like reading element data from the Store).

Copy link
Contributor

@bvaughn bvaughn May 12, 2020

Choose a reason for hiding this comment

The 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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try to do it in the next few days, thanks!

Copy link
Contributor Author

@bl00mber bl00mber May 13, 2020

Choose a reason for hiding this comment

The 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 setRootIDAndClearFiber = useCallback(
(id: number | null) => {
selectFiber(null, null);
setRootID(id);
},
[setRootID, selectFiber],
);

if (prevProfilingData !== profilingData) {
batchedUpdates(() => {
Expand All @@ -150,9 +182,9 @@ function ProfilerContextController({children}: Props) {
selectedElementRootID !== null &&
dataForRoots.has(selectedElementRootID)
) {
setRootID(selectedElementRootID);
setRootIDAndClearFiber(selectedElementRootID);
} else {
setRootID(firstRootID);
setRootIDAndClearFiber(firstRootID);
}
}
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -237,7 +245,7 @@ function ProfilerContextController({children}: Props) {
supportsProfiling,

rootID,
setRootID,
setRootID: setRootIDAndClearFiber,

isCommitFilterEnabled,
setIsCommitFilterEnabled,
Expand Down Expand Up @@ -268,6 +276,7 @@ function ProfilerContextController({children}: Props) {

rootID,
setRootID,
setRootIDAndClearFiber,

isCommitFilterEnabled,
setIsCommitFilterEnabled,
Expand Down