Repository navigation
Conversation
|
Hi @Hmache! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
dc230a9 to
d1c61f7
Compare
Refs react#37521 The `react-hooks/refs` validation (ValidateNoRefAccessInRender) flagged `fn !== otherFn` as "Cannot access refs during render" whenever `fn` was a function that reads a ref when called (e.g. a useCallback closing over ref.current). A `===`/`!==` comparison never invokes its operands, so merely comparing function identity cannot read `.current`. The BinaryExpression case validated its operands with validateNoRefValueAccess, which treats a Structure type with fn.readRefEffect the same as an actual ref value. Switch to validateNoDirectRefValueAccess, which only flags a direct RefValue operand (e.g. `ref.current === x`), matching the fact that a binary operator cannot call a function operand. Added a regression fixture (allow-comparing-ref-accessing-function-identity) confirming the pattern from the issue now compiles without error, while direct ref.current comparisons continue to correctly error. Ran the full `yarn snap` suite (1828 tests) with no regressions.
d1c61f7 to
111fdfd
Compare
|
Can you make sure the Rust version of the compiler has the same semantics? |
Port the ValidateNoRefAccessInRender change from the TypeScript compiler to the Rust port. The BinaryExpression case validated its operands with validate_no_ref_value_access, which treats a Structure type with read_ref_effect the same as an actual ref value, so `fn !== otherFn` was flagged as "Cannot access refs during render" whenever `fn` reads a ref when called. A `===`/`!==` comparison never invokes its operands, so switch to validate_no_direct_ref_value_access, which only flags a direct RefValue operand (e.g. `ref.current === x`). Without this, the allow-comparing-ref-accessing-function-identity fixture fails under `yarn snap --rust`. With it, `yarn snap --rust` passes all 1828 fixtures and `scripts/test-rust-port.sh ValidateNoRefAccessInRender` reports no TS/Rust divergence.
ah right, forgot the Rust port runs the same fixture set, pushed a50760f with the same change in validate_no_ref_access_in_render.rs, the BinaryExpression arm now uses the direct ref value check like the TS side |
[diff react/react@b618bbb4...07dde64d](react/react@b618bbb...07dde64) <details> <summary>React upstream changes</summary> - react/react#37710 - react/react#37814 - react/react#37778 - react/react#37688 - react/react#37796 </details> --------- Co-authored-by: next-js-bot[bot] <279046576+next-js-bot[bot]@users.noreply.github.com> Co-authored-by: Sebastian Sebbie Silbermann <[email protected]>
Summary
Fixes a false positive in the
react-hooks/refsvalidation (ValidateNoRefAccessInRender). Fixes #37521.Comparing a function with
===/!==was reported as "Cannot access refs during render" whenever that function reads a ref when called, for example auseCallbackthat closes overref.current:A binary operator never invokes its operands, so comparing function identity cannot read
.current. TheBinaryExpressioncase validated its operands withvalidateNoRefValueAccess, which treats aStructuretype carryingfn.readRefEffectthe same as an actual ref value. This switches it tovalidateNoDirectRefValueAccess, which only flags a directRefValueoperand, soref.current === xstill errors whilefn !== otherFnno longer does.How did you test this change?
allow-comparing-ref-accessing-function-identity(input +.expect.md) reproducing the pattern from the issue; it now compiles without error and the eval result is"different".ref.currentcomparisons continue to error (existing fixtures unchanged).yarn snap: 1828 tests, no regressions.validate_no_ref_access_in_render.rs):yarn snap --rustpasses all 1828 fixtures against the Rust backend, andscripts/test-rust-port.sh ValidateNoRefAccessInRenderreports no TS/Rust divergence.