SIGN IN SIGN UP
facebook / react UNCLAIMED

The library for web and native user interfaces.

0 0 0 JavaScript

[compiler] Preserve memoization for destructured props

The compiler currently fails to preserve manual memoization when components use rest spread destructuring for props:

```js
// OK
function Component(props) {
  const value = useMemo(() => compute(props.foo), [props.foo]);
}

// Manual memo could not be preserved
function Component({...props}) {
  const value = useMemo(() => compute(props.foo), [props.foo]);
}
```

The issue is that property accesses on rest-spread objects are treated as fully mutable.

This PR introduces a new `ShallowMutable` ValueKind for rest spreads that come specifically from props. When we access properties from a `ShallowMutable` value, they're treated as Frozen.

Closes #34313
L
Lauren Tan committed
8f7118afb8841bc92bb2e4f655ab4c55dcbc08e6
Parent: aad7c66