dillon1000/react
Commit
Browse files 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)
Changed paths5 files
First-parent comparisoncompiler/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 AddedPatch
Files changed
Rendering syntax-highlighted changes…