Skip to content

Refs rule in object#35826

Open
Liknox wants to merge 4 commits intofacebook:mainfrom
Liknox:refs-rule-in-object
Open

Refs rule in object#35826
Liknox wants to merge 4 commits intofacebook:mainfrom
Liknox:refs-rule-in-object

Conversation

@Liknox
Copy link

@Liknox Liknox commented Feb 20, 2026

Summary

  • Fixes a false positive in the react-hooks/refs ESLint rule triggered when multiple refs are stored in an object (e.g. const groupRefs = { group1: useRef(), group2: useRef() }) and passed to JSX (ref={groupRefs.group2}), which incorrectly reported “Cannot access ref value during render”.

  • Root cause: collectTemporariesSidemap aliased PropertyLoad results to the source object. As a result, env.set on a property-load lvalue resolved through temporaries and corrupted the object’s type (from Structure{Ref} to Ref), causing subsequent property loads to return RefValue instead of Ref.

  • Fix: remove PropertyLoad aliasing from collectTemporariesSidemap (the main validation already tracks types correctly) and update PropertyLoad handling in the main validator to propagate function type info from Structure types when the value is null.

Fixes #35813

Test plan

  • Added a new fixture allow-passing-refs-in-object-as-props that reproduces the false positive.
  • All 1840 compiler fixture tests pass.
  • Existing error detection for true ref violations is preserved (e.g. ref.current during render, calling ref-accessing functions during render).

@meta-cla meta-cla bot added the CLA Signed label Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments