dillon1000/react
Commit
Browse files [optim] All nested properties in refs are ref values
Forget currently removes memoization of callbacks that have `mutate` effects on
`ref` inner properties. @gsathya pointed out that our existing compiler behavior
is to (1) NOT extend mutable ranges for functions that mutate `ref.current` and
(2) extend mutable ranges for functions that mutate `ref.current.inner`.
```js
// input
function Component() {
const ref = useRef({ text: null });
const handleChange = useCallback((e) => {
ref.current.text = e.target.value;
});
return <input onChange={handleChange} />;
}
// output
function Component() {
const ref = useRef({ text: null });
// now unmemoized!
const handleChange = (e) => {
ref.current.text = e.target.value;
};Changed paths6 files
First-parent comparisoncompiler/packages/babel-plugin-react-forget/src/HIR/ObjectShape.ts ModifiedA compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-field-write-not-added-to-dep.expect.md AddedA compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-field-write-not-added-to-dep.js AddedM compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useCallback-set-ref-nested-property-dont-preserve-memoization.expect.md ModifiedA compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useCallback-set-ref-nested-property.expect.md AddedA compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useCallback-set-ref-nested-property.js AddedPatch
Files changed
Rendering syntax-highlighted changes…