Skip to content

Commit 77e9159

Browse files
committed
fix(react-devtools): print capture notes when the profile recorded no commits
1 parent bc041b3 commit 77e9159

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

‎src/cli/react-devtools/react-profile-command.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,22 @@ test('drill-down views read the saved recording, not a trimmed analysis', async
289289
assert.equal(saved.profile.commits.length, 3);
290290
assert.match((await run('report', 'Row')).text, /changed props: onPress 36 \(function\)/);
291291
});
292+
293+
test('a renderer that fails while another records nothing is named in the empty summary', async () => {
294+
const { app, run } = harness();
295+
const broken = Object.assign(Object.create(app.renderer), {
296+
getProfilingData: () => {
297+
throw new Error('second root gone');
298+
},
299+
});
300+
app.hook.rendererInterfaces.set(2, broken);
301+
await run('start');
302+
assert.equal(
303+
(await run('stop')).text,
304+
[
305+
'React profile: no commits recorded. Start profiling, then perform the interaction before stopping.',
306+
"Note: A React renderer's profile could not be read: second root gone",
307+
'',
308+
].join('\n'),
309+
);
310+
});

‎src/cli/react-devtools/react-profile-format.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,18 @@ test('the summary reports clean profiles and empty recordings in one line', () =
103103
);
104104
});
105105

106+
test('an empty recording still reports why part of it could not be read', () => {
107+
assert.equal(
108+
formatProfileSummary(
109+
analysis({ commitCount: 0, notes: ["A React renderer's profile could not be read: gone"] }),
110+
),
111+
[
112+
'React profile: no commits recorded. Start profiling, then perform the interaction before stopping.',
113+
"Note: A React renderer's profile could not be read: gone",
114+
].join('\n'),
115+
);
116+
});
117+
106118
test('lookup naming warns that unmounted components may be unnamed', () => {
107119
assert.match(
108120
formatProfileSummary(analysis({ naming: 'lookup' })),

‎src/cli/react-devtools/react-profile-format.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ export function formatProfileSummary(
2929
analysis: ReactProfileAnalysis,
3030
limit = DEFAULT_FINDING_LIMIT,
3131
): string {
32+
const notes = analysis.notes.map((note) => `Note: ${note}`);
3233
if (analysis.commitCount === 0) {
33-
return 'React profile: no commits recorded. Start profiling, then perform the interaction before stopping.';
34+
return [
35+
'React profile: no commits recorded. Start profiling, then perform the interaction before stopping.',
36+
...notes,
37+
].join('\n');
3438
}
3539
const lines = [headline(analysis)];
3640
const findings = analysis.findings.slice(0, limit);
@@ -45,7 +49,7 @@ export function formatProfileSummary(
4549
const hidden = analysis.findings.length - findings.length;
4650
if (hidden > 0) lines.push(`+${hidden} smaller findings (--limit ${analysis.findings.length})`);
4751
}
48-
for (const note of analysis.notes) lines.push(`Note: ${note}`);
52+
lines.push(...notes);
4953
if (analysis.naming === 'lookup') {
5054
lines.push(
5155
'Note: component names came from mounted elements; components unmounted during the profile are left out.',

0 commit comments

Comments
 (0)