Skip to content

[Compiler Bug]: Optional chaining not working with async try/catch function inside useEffect #35604

@a0m0rajab

Description

@a0m0rajab

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/#N4Igzg9grgTgxgUxALhAHQHacwgHgBwhgBcACAEwQDMBDKAGzKqgzmIEsINSAVGgIwAUASlLBs3UlDAIAolSoI2gkaQC8APjETSu0jTABPVqWasOXUwmJwAFgBEaxGqvGS9pYjEPb3H0nBcYGTkTjTqpADaALoA3Jj+eoEYwRRhAEwRoc4A-AB0VESyNHaC7MQIALbqWsmQ9Ah59BAA5sLxfroAvgFOdqSCCDAwRKJuibp1EA15QyMwggDkssNEVja27BgtpI7OyIsANKRzox2JXQl6l1i3Hoobey7tV13HMS+3VzDWsNyCV10AB4NIDSECAPSgu6kT43ECHEDJKjsFooEDsSqEEieQz4BBiUgABXoUBaWwA8vgLClSD0qCNqot+AIEPQALT4UnkjDsn4lYjswJY9gNGAQ8jsYKLDqYQTjUgQiHC-CipycDAAWQglGQpDQIBo9HoBswPTA6rAKIQYGJ3Mp1I1YHaCPAtggAHcAJIYCowDBGsAoWj0GRdIA

Repro steps

Using the next code reproduce the issue:

export default function Tab() {

  useEffect(() => {

    async function fetchData() {
      try {
        const data = [];
        const data2 = data?.forEach(item => console.log);
      } catch (error) {
        console.error('Error fetching Data:', error);
      }
    }


    fetchData();
  }, []);


  return (
    <>
    </>

  );
}

How often does this bug happen?

Every time

What version of React are you using?

Latest version

What version of React Compiler are you using?

Latest version

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