mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
f7d16db54480558fe792d04d44ae3b8d18603894
Improves memoization for cases such as #2409: ```javascript const x = []; useEffect(...); return <div>{x.map(item => <span>{item}</span>)}</div>; ``` We previously thought that the `x.map(...)` call mutated `x` since its kind was Mutable. However, in this case we can determine that the map call cannot mutate `x` (or anything else): the lambda does not mutate any free variables and does not mutate its arguments. This PR adds a new flag to function signatures, used for method calls only, that checks for such cases. The idea is that if the receiver is the only thing that is mutable — including that there are no args which are function expressions which mutate their parameters — then we can infer the effect as a read. See tests which confirm that function expressions which capture or mutate their params bypass the optimization.
Description
Languages
JavaScript
67.1%
TypeScript
29.4%
HTML
1.5%
CSS
1.1%
C++
0.6%
Other
0.2%