Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,66 @@ function countUniqueLocInEvents(events: Array<LoggerEvent>): number {
return count + seenLocs.size;
}

function getFailureReason(event: LoggerEvent): string {
switch (event.kind) {
case 'CompileError': {
const detail = event.detail;
if ('reason' in detail) {
return detail.reason;
}
return 'Unknown error';
}
case 'CompileDiagnostic':
return event.detail.reason;
case 'PipelineError':
return event.data;
default:
return 'Unknown error';
}
}

function printFailureDetails(
events: Array<LoggerEvent>,
label: string,
color: (s: string) => string,
): void {
const seen = new Map<string, LoggerEvent>();
for (const e of events) {
if (e.filename != null && e.fnLoc != null) {
const key = `${e.filename}:${e.fnLoc.start.line}:${e.fnLoc.start.column}`;
if (!seen.has(key)) {
seen.set(key, e);
}
Comment on lines +159 to +164

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deduplication key inconsistency with countUniqueLocInEvents

The deduplication key here uses e.fnLoc.start.line and e.fnLoc.start.column, while the existing countUniqueLocInEvents (line 126) uses ${e.fnLoc.start}:${e.fnLoc.end}. Since fnLoc.start is an object ({line, column}), the existing function's key stringifies to filename:[object Object]:[object Object], which effectively deduplicates by filename only.

This means the count shown in the summary line (e.g., "5 out of 10 components") could disagree with the number of items printed in verbose mode, since verbose correctly deduplicates by filename:line:column. This pre-existing bug in countUniqueLocInEvents isn't introduced by this PR, but combining it with the new verbose output will make the discrepancy visible to users.

Consider aligning the dedup logic—either fix countUniqueLocInEvents to use .start.line/.start.column/.end.line/.end.column, or extract a shared helper for building dedup keys.

Prompt To Fix With AI
This is a comment left during a code review.
Path: compiler/packages/react-compiler-healthcheck/src/checks/reactCompiler.ts
Line: 159-164

Comment:
**Deduplication key inconsistency with `countUniqueLocInEvents`**

The deduplication key here uses `e.fnLoc.start.line` and `e.fnLoc.start.column`, while the existing `countUniqueLocInEvents` (line 126) uses `${e.fnLoc.start}:${e.fnLoc.end}`. Since `fnLoc.start` is an object (`{line, column}`), the existing function's key stringifies to `filename:[object Object]:[object Object]`, which effectively deduplicates by filename only.

This means the count shown in the summary line (e.g., "5 out of 10 components") could disagree with the number of items printed in verbose mode, since verbose correctly deduplicates by `filename:line:column`. This pre-existing bug in `countUniqueLocInEvents` isn't introduced by this PR, but combining it with the new verbose output will make the discrepancy visible to users.

Consider aligning the dedup logic—either fix `countUniqueLocInEvents` to use `.start.line`/`.start.column`/`.end.line`/`.end.column`, or extract a shared helper for building dedup keys.

How can I resolve this? If you propose a fix, please make it concise.

} else {
// no location info, use a unique key so it's always printed
seen.set(`unknown-${seen.size}`, e);
}
}

if (seen.size === 0) {
return;
}

console.log(color(`\n${label} (${seen.size}):`));
for (const [, event] of seen) {
const file = event.filename ?? '<unknown>';
const loc =
event.fnLoc != null
? `:${event.fnLoc.start.line}:${event.fnLoc.start.column}`
: '';
const reason = getFailureReason(event);
console.log(color(` ${file}${loc} - ${reason}`));
}
}

export default {
run(source: string, path: string): void {
if (JsFileExtensionRE.exec(path) !== null) {
compile(source, path);
}
},

report(): void {
report(verbose?: boolean): void {
const totalComponents =
SucessfulCompilation.length +
countUniqueLocInEvents(OtherFailures) +
Expand All @@ -149,5 +201,10 @@ export default {
`Successfully compiled ${SucessfulCompilation.length} out of ${totalComponents} components.`,
),
);

if (verbose) {
printFailureDetails(ActionableFailures, 'Actionable failures', chalk.red);
printFailureDetails(OtherFailures, 'Other failures', chalk.yellow);
}
},
};
8 changes: 7 additions & 1 deletion compiler/packages/react-compiler-healthcheck/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ async function main() {
type: 'string',
default: '**/+(*.{js,mjs,jsx,ts,tsx}|package.json)',
})
.option('verbose', {
alias: 'v',
description: 'display per-component failure details',
type: 'boolean',
default: false,
})
.parseSync();

const spinner = ora('Checking').start();
Expand All @@ -48,7 +54,7 @@ async function main() {
}
spinner.stop();

reactCompilerCheck.report();
reactCompilerCheck.report(argv.verbose);
strictModeCheck.report();
libraryCompatCheck.report();
}
Expand Down
Loading