@samitouri / QOS-React / commits / ac1a986ace

Handle RTE in profiler when commit does not contain selected node

Brian Vaughn committed Mar 19, 2019 at 11:19 UTC ac1a986acecbe146a2efd113f7fa336308a6ab33
1 file changed +19 -11
src/devtools/views/Profiler/CommitFlamegraph.js
+19 -11
@@ -86,21 +86,29 @@ function CommitFlamegraph({
86 rootID: ((rootID: any): number),
87 });
88
89 - const selectedChartNodeIndex = useMemo(
90 - () =>
91 - selectedFiberID === null
92 - ? 0
93 - : ((chartData.idToDepthMap.get(selectedFiberID): any): number) - 1,
94 - [chartData, selectedFiberID]
95 - );
89 + const selectedChartNodeIndex = useMemo<number>(() => {
90 + if (selectedFiberID === null) {
91 + return 0;
92 + }
93 + // The selected node might not be in the tree for this commit,
94 + // so it's important that we have a fallback plan.
95 + const depth = chartData.idToDepthMap.get(selectedFiberID);
96 + return depth !== undefined ? depth - 1 : 0;
97 + }, [chartData, selectedFiberID]);
98
99 const selectedChartNode = useMemo(() => {
98 - if (selectedFiberID === null) {
100 + let chartNode = null;
101 + if (selectedFiberID !== null) {
102 + chartNode = ((chartData.rows[selectedChartNodeIndex].find(
103 + chartNode => chartNode.id === selectedFiberID
104 + ): any): ChartNode);
105 + }
106 + // The selected node might not be in the tree for this commit,
107 + // so it's important that we have a fallback plan.
108 + if (chartNode == null) {
109 return chartData.rows[0][0];
110 }
101 - return ((chartData.rows[selectedChartNodeIndex].find(
102 - chartNode => chartNode.id === selectedFiberID
103 - ): any): ChartNode);
111 + return chartNode;
112 }, [chartData, selectedFiberID, selectedChartNodeIndex]);
113
114 const itemData = useMemo<ItemData>(