Skip to content

[Compiler Bug]: Destructuring props leads to under-optimized component #36281

@srubin

Description

@srubin

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/#N4Igzg9grgTgxgUxALhAMygOzgFwJYSYAEAggBTBEBuAhgDZgA0RAdGwA4wTthEC+ASiLAAOsSJxCYHETREAvETK06UBGCHyAfNXpqwLALY12ZZZp1UiAaiKduBtBAgCA3GKJEYCHLGIAeABM8Ki1gNGV6DT5-AHpg0PdMPjExDGx8QiIAITJ7HiFRcUlMaVkFJRV9C11VdSMTMyoaq1t8x2c3Dy8fPyIgkLCI9pYVaLiErSS+EEYQErQ8AHMUECLPWNjJQ3Y8OhpMzABZCECEZCIREHo6K7EZubAACwgAdwBJTBwEGEwolDQUQQfCAA

Repro steps

When we destructure a component's props into another object, the compiled component is less optimal than it could be. In the playground for component A, we only need props.foo in the function, but the compiled component checks for props changing. If we don't use the destructed props (see B) then the compiled result checks for props.foo changing, which is more optimal.

Destructuring props into an object in a component is a fairly common pattern, so this has the potential to significantly reduce the efficiency of React Compiler optimizations.

How often does this bug happen?

Every time

What version of React are you using?

18.2.0

What version of React Compiler are you using?

0.0.0-experimental-a1856f3-20260409

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bugType: Bug

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions