Skip to content

[compiler] Fix false positive in refs rule for refs stored in objects#35819

Open
apoorvdarshan wants to merge 1 commit intofacebook:mainfrom
apoorvdarshan:fix-refs-rule-false-positive
Open

[compiler] Fix false positive in refs rule for refs stored in objects#35819
apoorvdarshan wants to merge 1 commit intofacebook:mainfrom
apoorvdarshan:fix-refs-rule-false-positive

Conversation

@apoorvdarshan
Copy link

@apoorvdarshan apoorvdarshan commented Feb 18, 2026

Summary

  • Fixes a false positive in the react-hooks/refs ESLint rule where storing multiple refs in an object (const groupRefs = {group1: useRef(), group2: useRef()}) and passing them as JSX props (ref={groupRefs.group2}) incorrectly reported "Cannot access ref value during render"
  • Root cause: collectTemporariesSidemap aliased PropertyLoad results to the source object, so env.set on a property load lvalue would resolve through the temporary chain and corrupt the object's type (from Structure{Ref} to Ref), causing subsequent property loads to produce RefValue instead of Ref
  • The fix removes PropertyLoad aliasing from collectTemporariesSidemap (the main validation loop already tracks types correctly) and adjusts PropertyLoad in the main validation to propagate function type info from Structure types when value is null

Fixes #35813

Test plan

  • Added 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)
  • Verify with the reproduction from the issue (StackBlitz sandbox)

When multiple refs are stored in an object (e.g. `{group1: useRef(), group2: useRef()}`),
the `react-hooks/refs` validation incorrectly reported "Cannot access ref value during
render" on the second property access. This happened because `collectTemporariesSidemap`
aliased PropertyLoad results to the source object, causing `env.set` on the property load
lvalue to corrupt the object's type through the temporary chain.

The fix removes PropertyLoad aliasing from `collectTemporariesSidemap` (the main
validation loop already tracks types correctly through `env.set`), and adjusts the
PropertyLoad case in the main validation to propagate function type info from Structure
types when the value is null.

Fixes facebook#35813
@meta-cla meta-cla bot added the CLA Signed label Feb 18, 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.

[eslint-plugin-react-hooks] Bug: react-hooks/refs rule reporting false positive

1 participant

Comments