mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
d7db416167c1fcc1c1938d2880c8b0f919fd376b
This is one approach to testing whether useEffect dependencies are memoized. The idea is based off the observation that the only reason dependencies wouldn't be memoized (other than compiler bugs) is that they are mutated later. If they're mutated later, then the dep array will have a mutable range which encompasses the InstructionId of the useEffect call. So we look for that pattern and throw a validation error. The downside of this approach is that we might reject code that happens to be valid: specifically, that the lack of memoization isn't a problem in practice because the effect won't trigger a loop. But (per test plan) this doesn't seem to introduce that many new bailouts on www. Rather than implement a complex validation that checks whether we un-memoized something that was memoized in the input, it seems more practical to: 1. Enable this more comprehensive validation against any form of un-memo'd effect dependency 2. Flip the default for hooks (to assume they follow the rules), which will fix the primary cause of Forget pessimistically not memoizing dependencies. ## Test Plan Synced to www and checked output via the upgrade script: a few components stop getting memoized bc they have un-memoized effect dependencies. Let's chat!
Description
Languages
JavaScript
67.1%
TypeScript
29.4%
HTML
1.5%
CSS
1.1%
C++
0.6%
Other
0.2%