Skip to content

Commit

Permalink
Profiler bugfix for filtering out all commits after selecting a fiber
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Aug 18, 2019
1 parent 95ca079 commit 4697f5b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 26 deletions.
17 changes: 13 additions & 4 deletions src/devtools/views/Profiler/Profiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function Profiler(_: {||}) {
didRecordCommits,
isProcessingData,
isProfiling,
selectedCommitIndex,
selectedFiberID,
selectedTabID,
selectTab,
Expand Down Expand Up @@ -67,10 +68,18 @@ function Profiler(_: {||}) {
break;
case 'flame-chart':
case 'ranked-chart':
if (selectedFiberID !== null) {
sidebar = <SidebarSelectedFiberInfo />;
} else {
sidebar = <SidebarCommitInfo />;
// TRICKY
// Handle edge case where no commit is selected because of a min-duration filter update.
// In that case, the selected commit index would be null.
// We could still show a sidebar for the previously selected fiber,
// but it would be an odd user experience.
// TODO (ProfilerContext) This check should not be necessary.
if (selectedCommitIndex !== null) {
if (selectedFiberID !== null) {
sidebar = <SidebarSelectedFiberInfo />;
} else {
sidebar = <SidebarCommitInfo />;
}
}
break;
default:
Expand Down
44 changes: 24 additions & 20 deletions src/devtools/views/Profiler/ProfilerContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,28 +127,32 @@ function ProfilerContextController({ children }: Props) {
const [rootID, setRootID] = useState<number | null>(null);

if (prevProfilingData !== profilingData) {
setPrevProfilingData(profilingData);

const dataForRoots =
profilingData !== null ? profilingData.dataForRoots : null;
if (dataForRoots != null) {
const firstRootID = dataForRoots.keys().next().value || null;

if (rootID === null || !dataForRoots.has(rootID)) {
let selectedElementRootID = null;
if (selectedElementID !== null) {
selectedElementRootID = store.getRootIDForElement(selectedElementID);
}
if (
selectedElementRootID !== null &&
dataForRoots.has(selectedElementRootID)
) {
setRootID(selectedElementRootID);
} else {
setRootID(firstRootID);
batchedUpdates(() => {
setPrevProfilingData(profilingData);

const dataForRoots =
profilingData !== null ? profilingData.dataForRoots : null;
if (dataForRoots != null) {
const firstRootID = dataForRoots.keys().next().value || null;

if (rootID === null || !dataForRoots.has(rootID)) {
let selectedElementRootID = null;
if (selectedElementID !== null) {
selectedElementRootID = store.getRootIDForElement(
selectedElementID
);
}
if (
selectedElementRootID !== null &&
dataForRoots.has(selectedElementRootID)
) {
setRootID(selectedElementRootID);
} else {
setRootID(firstRootID);
}
}
}
}
});
}

const startProfiling = useCallback(
Expand Down
10 changes: 9 additions & 1 deletion src/devtools/views/Profiler/SidebarSelectedFiberInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default function SidebarSelectedFiberInfo(_: Props) {
}

type WhatChangedProps = {|
commitIndex: number,
commitIndex: number | null,
fiberID: number,
profilerStore: ProfilerStore,
rootID: number,
Expand All @@ -101,6 +101,14 @@ function WhatChanged({
profilerStore,
rootID,
}: WhatChangedProps) {
// 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 (commitIndex === null) {
return null;
}

const { changeDescriptions } = profilerStore.getCommitData(
((rootID: any): number),
commitIndex
Expand Down
2 changes: 1 addition & 1 deletion src/devtools/views/Profiler/SnapshotSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default function SnapshotSelector(_: Props) {
return null;
}, [filteredCommitIndices, selectedCommitIndex]);

// TODO (profiling) This should be managed by the context controller (reducer).
// TODO (ProfilerContext) This should be managed by the context controller (reducer).
// It doesn't currently know about the filtered commits though (since it doesn't suspend).
// Maybe this component should pass filteredCommitIndices up?
if (selectedFilteredCommitIndex === null) {
Expand Down

0 comments on commit 4697f5b

Please sign in to comment.