react icon indicating copy to clipboard operation
react copied to clipboard

[Compiler Bug]: react-compiler-healthcheck 1.0.0 always reports 100% — isActionableDiagnostic switches on removed ErrorSeverity members

Open Ninfendo opened this issue 4 months ago • 3 comments

What happened

[email protected] reports a perfect score on every codebase, because it can never record a failure. isActionableDiagnostic switches on ErrorSeverity members that no longer exist in the enum the same bundle ships, so every CompileError falls through to default: and throws — inside a logger whose caller swallows it.

Both halves are in healthcheck's own dist, so this is not a version-mismatch between packages:

// dist, ~line 18376 — the enum it bundles
ErrorSeverity2["Error"]   = "Error";
ErrorSeverity2["Warning"] = "Warning";
ErrorSeverity2["Hint"]    = "Hint";
ErrorSeverity2["Off"]     = "Off";

// dist, ~line 54314 — the switch, still on the pre-1.0 member names
function isActionableDiagnostic(detail) {
  switch (detail.severity) {
    case ErrorSeverity.InvalidReact:              // undefined
    case ErrorSeverity.InvalidJS:                 // undefined
      return true;
    case ErrorSeverity.InvalidConfig:             // undefined
    case ErrorSeverity.Invariant:                 // undefined
    case ErrorSeverity.CannotPreserveMemoization: // undefined
    case ErrorSeverity.Todo:                      // undefined
      return false;
    default:
      throw new Error(`Unhandled error severity \`${detail.severity}\``);
  }
}

All six case labels evaluate to undefined. A real detail.severity of "Error" matches none of them, hits default, and throws Unhandled error severity \Error`. The throw happens inside logger.logEvent, and compile()wraps the run intry { … } catch {}— so the exception is swallowed,ActionableFailures/OtherFailuresstay empty,totalComponents === successes`, and the summary can only ever print "N out of N". It also aborts that file early, so successes after the first failure in the same file are lost too.

Repro

Any project with at least one bail-out. In a monorepo app I measured independently:

$ bunx [email protected] --src "apps/monitoring/src/**/*.{ts,tsx}"
Successfully compiled 24 out of 24 components.

Running @babel/core + [email protected] directly over the same glob with a capturing logger — same options healthcheck uses (noEmit, compilationMode: 'infer', panicThreshold: 'critical_errors') — gives 24 compiled, 6 bailed (80%). Same 24 successes; the 6 failures are simply never recorded.

Across 651 files the direct run reports 926 compiled / 73 bailed (92.7%); healthcheck reports 100% for every app.

Why it matters

The failure is silent and biased in the dangerous direction. A team runs healthcheck, sees 100%, and concludes there is nothing to investigate — the exact opposite of the truth, and with no error output to suggest otherwise. It also makes healthcheck useless as a before/after signal for an adoption rollout, which is its main use.

Suggested fix

Map the switch onto the current enum (Error / Warning / Hint / Off), and make the default non-fatal — an unrecognised severity should count the diagnostic and warn, never throw. Given the throw is swallowed one frame up, a catch that at minimum logged would have surfaced this immediately; that seems worth doing regardless.

Version: [email protected], [email protected], React 19.2.5, Node 24.

Ninfendo avatar Jul 27 '26 22:07 Ninfendo

Root Cause

isActionableDiagnostic in react-compiler-healthcheck switches on the old pre-1.0 ErrorSeverity member names (InvalidReact, InvalidJS, InvalidConfig, Invariant, CannotPreserveMemoization, Todo) which no longer exist. The current enum only has Error, Warning, Hint, and Off.

All six case labels evaluate to undefined, so every real severity string hits default: and throws. The throw is swallowed by compile()'s empty catch {}, making ActionableFailures and OtherFailures permanently empty — hence 100% success for every codebase.

Fix

  • Updated the switch to use current ErrorSeverity values (Error = actionable, Warning/Hint/Off = not actionable)
  • Replaced the deprecated CompilerErrorDetailOptions import with CompileErrorDetail (which actually has the severity field)
  • Made the default case non-fatal (returns false) so unknown severities don't throw and silently lose the diagnostic

PR submitted.

stareezy-1 avatar Aug 04 '26 07:08 stareezy-1

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

github-actions[bot] avatar Nov 05 '26 15:11 github-actions[bot]

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!

github-actions[bot] avatar Nov 12 '26 16:11 github-actions[bot]