Profiler bugfix for filtering out all commits after selecting a fiber

This commit is contained in:
Brian Vaughn
2019-08-18 08:34:40 -07:00
parent 95ca079556
commit 4697f5b379
4 changed files with 45 additions and 24 deletions
+13 -4
View File
@@ -28,6 +28,7 @@ function Profiler(_: {||}) {
didRecordCommits,
isProcessingData,
isProfiling,
selectedCommitIndex,
selectedFiberID,
selectedTabID,
selectTab,
@@ -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:
+22 -18
View File
@@ -127,28 +127,32 @@ function ProfilerContextController({ children }: Props) {
const [rootID, setRootID] = useState<number | null>(null);
if (prevProfilingData !== profilingData) {
setPrevProfilingData(profilingData);
batchedUpdates(() => {
setPrevProfilingData(profilingData);
const dataForRoots =
profilingData !== null ? profilingData.dataForRoots : null;
if (dataForRoots != null) {
const firstRootID = dataForRoots.keys().next().value || null;
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);
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(
@@ -89,7 +89,7 @@ export default function SidebarSelectedFiberInfo(_: Props) {
}
type WhatChangedProps = {|
commitIndex: number,
commitIndex: number | null,
fiberID: number,
profilerStore: ProfilerStore,
rootID: number,
@@ -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
@@ -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) {