Skip to content

[Compiler Bug]: function outlining changes runtime semantics inside expressions #33138

Open
@nikeee

Description

@nikeee

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-compiler (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/#N4Igzg9grgTgxgUxALhAMygOzgFwJYSYAEAwhALYAOhCmOAFAJRHAA6xRMCOsxAPAGUcMPJgDmeNAE8iANwCGAGygIAvMADa7IjqL0mRVQD4WRAL6MAdDghCR4pgBptu-c2OmuPGMVbh5ACbyYAF+5swA1ER+fs4cOvQY2PiERGgQEAbA4URRMSBxunpJuATE6ZnM2RbWtsKiYk4uALpmAPRGANzsZiBmQA

Repro steps

function Component() {
  return <Stringify value={[
    (() => { }).toString(),
    (() => { }) + "",
    (function foo() { }) + "",
    (function foo() { }).toString(),
  ]}/>;
}

() => { } gets outlined to a temp global function, which results in a different toString value:

  • (() => { return "sadasd" }) + "" -> '() => { return "sadasd" }'
  • (function _temp2() { return "sadasd"; }).toString() -> 'function _temp2() {\n return "sadasd";\n}'

Same probably happens to components that take functions as props and apply .toString() on them for whatever reason.

May not be a bug depending on how react defines this case. I think the only way of fixing this is not to outline lambdas in expressions. But I think this breaks the intended optimization entirely, so this might be just defined as an intended incompability.

How often does this bug happen?

Every time

What version of React are you using?

19

What version of React Compiler are you using?

rc1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions