dillon1000/react

Commit

Preserve memoization guarantees for useCallback

Improves `@enablePreserveExistingMemoizationGuarantees` for the useCallback 
case. Similar to useMemo, we add an explicit `Memoize` instruction for the 
callback function itself _and_ for its dependencies. This means we'll assume the 
callback doesn't mutate any captured variables. 

TODO: check this with cases involving refs (should be allowed, but also not 
accidentally freeze the ref) and reassignment of locals (should be disallowed, 
though that might just be a validation we're missing today)
Browse files
Changed paths5 files
First-parent comparison
M compiler/packages/babel-plugin-react-forget/src/Inference/DropManualMemoization.ts ModifiedA compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useCallback-maybe-modify-free-variable-dont-preserve-memoization-guarantee.expect.md AddedA compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useCallback-maybe-modify-free-variable-dont-preserve-memoization-guarantee.js AddedA compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useCallback-maybe-modify-free-variable-preserve-memoization-guarantee.expect.md AddedA compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useCallback-maybe-modify-free-variable-preserve-memoization-guarantee.js Added
Patch

Files changed

Rendering syntax-highlighted changes…