Skip to content

[Compiler Bug]: Overloads cause wrong function to be exported with gating #35991

@danteissaias

Description

@danteissaias

What kind of issue is this?

  • React Compiler core (the JS output is incorrect, or your app works incorrectly after optimization)
  • babel-plugin-react-compiler (build issue installing or using the Babel plugin)
  • eslint-plugin-react-hooks (build issue installing or using the eslint plugin)
  • react-compiler-healthcheck (build issue installing or using the healthcheck script)

Link to repro

https://playground.react.dev/#N4Igzg9grgTgxgUxALhASwLYAcIwC4AEwBUYCAynrggQL4EBmMEGBAOiAHScD0YVMBGD4CEHANxsAdtIQAPHPkZQpcPGghSSZckLAapACgCUyArrD7NBAD4EpUADaPJU+YsIMVag9op6DAB4AFQA+QzJHBDVcMwiAzTMLKyljAgBeUIJg02zbeycXWQVcT291a1J-SyCww2kCAkjogQB+OLIaxPME1Iys4Olc5N87YPyHZyIGgkE8WC0qympDCLTM6a1GgjhNfibejKbOTpTXbYI0BgJDAEJTgzS5hYLnc+3nmC1mmJgCVoOUV+8S6fTMD0071oxlctBAABoQLspAw0ABzFDobClAh4ACeWBoxAACo4oGi0FIAPJYCpSMB0RjMVgAcgARgBDNkIRwAWiwZIpUl5gg5al5u2waCiMB4ABM0PwWa5pIZgDM0Rz1FI0WZ1VtGpBYIgzBwAEoIMV4ADCLCw0oQMAAYpb5oInY4OWiwBx4TNGpgPORCXArmhHQA5DkYBCm9BgW1SmUAUSkXKict9M1ofqk9DAWsVqKEBFJ5MpNLpYBhCPAAAsIAB3ACSUjwjrTjjAKAYHK7CFoQA

Repro steps

  1. Compile a function with TypeScript overload signatures with gating enabled:
import { useStore } from "../stores/store";

// Overload signatures
export function useSession(): Session | null;
export function useSession<T>(selector: (session: Session) => T): T | null;
// Implementation
export function useSession<T>(
  selector?: (session: Session) => T
): Session | T | null {
  return useStore((s) => {
    const session = s.session;
    if (!session) return null;
    return selector ? selector(session) : session;
  });
}
  1. The presence of overload signatures causes export to be placed on the wrong function:
// Wrong - unoptimized variant is exported
export function useSession_unoptimized<T>(...) { ... }

// Wrong - dispatcher is not exported
function useSession(arg0) { ... }

Expected: useSession should be exported, not useSession_unoptimized

How often does this bug happen?

Every time

What version of React are you using?

19.2.4

What version of React Compiler are you using?

1.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bugType: Bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions