Skip to content

[Compiler Bug]: React Compiler throws hard errors for valid JS inside callbacks (non-render paths) #35570

@Ranamalsingh12

Description

@Ranamalsingh12

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/#N4Igzg9grgTgxgUxALhAcimBACOAbASwQDsAXNAbgB1iaCBbABwhlOwCpsBDMbAJQRc4bAGYwI9bGhiDhlGjQQAPZq2wATBCK5Q8oqMWEEIxbAEFGjABQBKbMBrZcJsGwDaCGOJgAabFlIAUS8WAF1sAF5+WVIAOkwEAGVSLlIEAB5XGAJiAHNsAB9sYl08AD4rErw8G2paU2diV2wACy5idTwEAGFCOABrSO4wAE9DbFtIsvtHJ2xSGBGZhrnG5pkwXTYorgB3LgJRLn6EAQBHKARXWzrZ1YB6e+xAGXJooTZuiUYCLph5lvEu14LU8CDuc0e2CoIAAKhB1BBkNhElBLCw2AA3Lh4S7YABGeAgA14VjgJnUh2MxGxfkJuQIcBp2AgjFIVOxuDaORyuT8CFIcBs4KckN2hxaOW480W90ZApa-hSaXoJFI0OF2AIIgmGy2AH5Yp5vHYHCtVv5+cFvFZdXpDSEYLEVWAwFxcghahqnDJSLBiHVzdgAL4KM1OAJWliVUqes1B3CpOAKqwe5aBiMOqxoRISfkSvLYXaqwviPJoWOrEMNIO3Bo+v0TcHpCkYxUjLoRYDAbCMLjqCl5JEAJgADMGg2UNek8VBSKQTMziL0Gf1O20Ol1lwMJ1v+ul7jO5yZJ2H7EaWNgAGSX7DpRhlYDnmBB-f3qurfctk9OWNVmg8MY4GwEQDCMBdtBOc5LmuGwkQABXEegCCwdJZiKbt1FSLgkSyHlgzQ+xsCfJFu2dV13RwhY8PjKtplNb1+QbbtiMIsi3QQJE0AAMQOLp1DQYNgzqKsQB8EAyWIEQCFyFAQAYVQ2FIEZGBwbs4JxeliAAeVZKleHjMQJCkPEuDxBA8AAWkYDScgsmR3gsskmB+Tx7gpVx5HqKx6OwR4nO+PBUipABZeEOKhEBsTwdViHjV02TAKSrmwdSoE0nS2RcWpRPAFoIF2ABJMhPGpPAwBQbQyoQIMgA

Repro steps

I was implementing a normal login flow in a client component using the React Compiler.
The issue occurred inside an event handler callback (handleSubmit) that runs in response to a form submit.

Inside this callback, I wrapped an async authentication call in a try/catch block and performed basic result checking using optional chaining (e.g. if (result?.error)), which is valid JavaScript and works correctly at runtime.

As soon as this code was analyzed by the React Compiler, it threw a hard compilation error saying that value blocks (optional chaining, conditionals, etc.) are not supported inside try/catch. This happens even though the code is not render logic, not memoized, and not part of React’s reactive graph.

I wasn’t doing anything unusual or advanced — just standard error handling inside an async callback. Removing the optional chaining or restructuring the logic avoids the error, but that requires large mechanical refactors across the codebase.

The issue reproduces consistently whenever optional chaining (or similar expressions) is used inside a try/catch within a callback function.

How often does this bug happen?

Every time

What version of React are you using?

latest

What version of React Compiler are you using?

latest

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