Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 of 4 tasks
nikeee opened this issue May 7, 2025 · 0 comments
Open
1 of 4 tasks
Labels
Component: React Compiler Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug Type: Bug

Comments

@nikeee
Copy link
Contributor

nikeee commented May 7, 2025

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

@nikeee nikeee added Type: Bug Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug Component: React Compiler labels May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: React Compiler Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug Type: Bug
Projects
None yet
Development

No branches or pull requests

1 participant