dillon1000/react

Commit

[compiler] Allow all hooks to take callbacks which access refs, but ban hooks from taking direct ref value arguments

Summary:
This brings the behavior of ref mutation within hook callbacks into alignment with the behavior of global mutations--that is, we allow all hooks to take callbacks that may mutate a ref. This is potentially unsafe if the hook eagerly calls its callback, but the alternative is excessively limiting (and inconsistent with other enforcement).

This also bans *directly* passing a ref.current value to a hook, which was previously allowed.

ghstack-source-id: e66ce7123ecf4a905adab957970d0ee5d41245e0
Pull Request resolved: https://github.com/facebook/react/pull/30917
Browse files
Changed paths9 files
First-parent comparison
M compiler/packages/babel-plugin-react-compiler/src/HIR/Globals.ts ModifiedM compiler/packages/babel-plugin-react-compiler/src/HIR/ObjectShape.ts ModifiedM compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoRefAccesInRender.ts ModifiedA compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.hook-ref-value.expect.md AddedA compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.hook-ref-value.js AddedA compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-ref-callback.expect.md AddedA compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-ref-callback.js AddedA compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useImperativeHandle-ref-mutate.expect.md AddedA compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useImperativeHandle-ref-mutate.js Added
Patch

Files changed

Rendering syntax-highlighted changes…