From 4acc2ce7c7d391234d07243bde35e8c84643db02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C2=ABSergei?= Date: Thu, 14 May 2026 15:29:36 +0300 Subject: [PATCH] [devtools] Ignore missing nodes in ranked chart --- .../src/__tests__/profilingCharts-test.js | 68 +++++++++++++++++++ .../views/Profiler/RankedChartBuilder.js | 2 +- 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/packages/react-devtools-shared/src/__tests__/profilingCharts-test.js b/packages/react-devtools-shared/src/__tests__/profilingCharts-test.js index da20511a650e..fbe0ad49e112 100644 --- a/packages/react-devtools-shared/src/__tests__/profilingCharts-test.js +++ b/packages/react-devtools-shared/src/__tests__/profilingCharts-test.js @@ -10,6 +10,8 @@ import type Store from 'react-devtools-shared/src/devtools/store'; import {getVersionedRenderImplementation} from './utils'; +import {ElementTypeFunction} from 'react-devtools-shared/src/frontend/types'; +import {getChartData as getRankedChartDataFromBuilder} from 'react-devtools-shared/src/devtools/views/Profiler/RankedChartBuilder'; describe('profiling charts', () => { let React; @@ -31,6 +33,72 @@ describe('profiling charts', () => { const {render} = getVersionedRenderImplementation(); + it('ranked chart should ignore durations for nodes missing from the commit tree', () => { + const commitTree = { + rootID: 1, + nodes: new Map([ + [ + 1, + { + children: [2], + compiledWithForget: false, + displayName: null, + hocDisplayNames: null, + id: 1, + key: null, + parentID: 0, + treeBaseDuration: 0, + type: ElementTypeFunction, + }, + ], + [ + 2, + { + children: [], + compiledWithForget: false, + displayName: 'Parent', + hocDisplayNames: null, + id: 2, + key: null, + parentID: 1, + treeBaseDuration: 10, + type: ElementTypeFunction, + }, + ], + ]), + }; + const profilerStore = { + getCommitData() { + return { + fiberActualDurations: new Map([ + [2, 10], + [3, 5], + ]), + fiberSelfDurations: new Map([ + [2, 10], + [3, 5], + ]), + }; + }, + }; + + const chartData = getRankedChartDataFromBuilder({ + commitIndex: 0, + commitTree, + profilerStore, + rootID: 123, + }); + + expect(chartData.nodes).toEqual([ + { + id: 2, + label: 'Parent (10ms)', + name: 'Parent', + value: 10, + }, + ]); + }); + function getFlamegraphChartData(rootID, commitIndex) { const commitTree = store.profilerStore.profilingCache.getCommitTree({ commitIndex, diff --git a/packages/react-devtools-shared/src/devtools/views/Profiler/RankedChartBuilder.js b/packages/react-devtools-shared/src/devtools/views/Profiler/RankedChartBuilder.js index 8cec8c6b924f..b5e3189c238a 100644 --- a/packages/react-devtools-shared/src/devtools/views/Profiler/RankedChartBuilder.js +++ b/packages/react-devtools-shared/src/devtools/views/Profiler/RankedChartBuilder.js @@ -58,7 +58,7 @@ export function getChartData({ const node = nodes.get(id); if (node == null) { - throw Error(`Could not find node with id "${id}" in commit tree`); + return; } const {displayName, key, parentID, type, compiledWithForget} = node;