From ac1a986acecbe146a2efd113f7fa336308a6ab33 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Tue, 19 Mar 2019 11:19:30 -0700 Subject: [PATCH] Handle RTE in profiler when commit does not contain selected node --- .../views/Profiler/CommitFlamegraph.js | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/devtools/views/Profiler/CommitFlamegraph.js b/src/devtools/views/Profiler/CommitFlamegraph.js index 75967d4b59..f8ab0bff25 100644 --- a/src/devtools/views/Profiler/CommitFlamegraph.js +++ b/src/devtools/views/Profiler/CommitFlamegraph.js @@ -86,21 +86,29 @@ function CommitFlamegraph({ rootID: ((rootID: any): number), }); - const selectedChartNodeIndex = useMemo( - () => - selectedFiberID === null - ? 0 - : ((chartData.idToDepthMap.get(selectedFiberID): any): number) - 1, - [chartData, selectedFiberID] - ); + const selectedChartNodeIndex = useMemo(() => { + if (selectedFiberID === null) { + return 0; + } + // The selected node might not be in the tree for this commit, + // so it's important that we have a fallback plan. + const depth = chartData.idToDepthMap.get(selectedFiberID); + return depth !== undefined ? depth - 1 : 0; + }, [chartData, selectedFiberID]); const selectedChartNode = useMemo(() => { - if (selectedFiberID === null) { + let chartNode = null; + if (selectedFiberID !== null) { + chartNode = ((chartData.rows[selectedChartNodeIndex].find( + chartNode => chartNode.id === selectedFiberID + ): any): ChartNode); + } + // The selected node might not be in the tree for this commit, + // so it's important that we have a fallback plan. + if (chartNode == null) { return chartData.rows[0][0]; } - return ((chartData.rows[selectedChartNodeIndex].find( - chartNode => chartNode.id === selectedFiberID - ): any): ChartNode); + return chartNode; }, [chartData, selectedFiberID, selectedChartNodeIndex]); const itemData = useMemo(