Skip to content

[Compiler Bug]: React Compiler does not compile a component if it contains a reference to Object.entries within a try block within an async function #34761

@ferrybig

Description

@ferrybig

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/#N4Igzg9grgTgxgUxALhAHQHaYJYFsAOEMALgAQBKCAhnMQDSnClRgIDKxVxCpAvqQDMYEXKTQgY1WuIDcmTAKgZa2CBlIAxIrgDq2YgAsA8gCMAVglobhuAKIZiMbAjAAKJgOcAbACZg+AJSMmKSkcGpgZAZUGD5e7FAmuPqkALykVGAAnsqkrggAbggOQakAfMFYxI5ZlWhkoQJEeeEYkaQA2gDWCFkMBVReUAgAuqQQAqSmFrQAdMWOzm6eCL5gAUHA8sT1rZDxs14QAOauPX2kHE4YpwNDCBtyVbzb-HBccAZ5D3XEL+p8J4hUiSYiwdSuYGhAA8Jig1TUpGIWXwCFS4jhCKwIHGGAAwl5sHAuqlgNFYvE2Ilkn8ylSkvpoQB6THENRlYEBJ7-TAIAAehBIpB8CAEVCgXjIWhgun0xnMlmI1hE9kWLhkIDoIFanmOKBAeEFZGRqMYpAACkNjtgMEZ8MRVG0+IIbKQAOQmKgmVYAWnwVptPskNGIPvCBGw8RgTJ82EibqBGHcwKZTPD+EjXEdAFkICLkGIQIMvOJMPwwFmwCt-JaoNbbfbHesNVqwAYIAB3ACSDgQMAwgzAKDFXlYvCAA

Repro steps

  1. Go to https://playground.react.dev/ (make sure to clear your site data before loading this, because it likes to autosave your code, even if it causes the sandbox to crash)
  2. Paste the following
import React, { useState } from "react";

function FormWithObjectFromEntries({ fields }) {
  const handleSubmit = async (event) => {
    try {
      for (const [key, value] of Object.entries(fields)) {
        console.log(key, String(value));
      }
    } catch (e) {}
  };

  return (
    <button type="button" onClick={handleSubmit}>
      Submit
    </button>
  );
}

export default FormWithObjectFromEntries;

(Note that this is a minimal reproducible example, I got this issue in a larger codebase)

Expected:

React compiler compiles the component

Actual (in real code base)

React compiler skips this component

Actual (In playground)

The playground crashes

How often does this bug happen?

Every time

What version of React are you using?

19.2.0

What version of React Compiler are you using?

[email protected]

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