You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Compiler Bug]: InvalidReact: Ref values (the current property) may not be accessed during render. False Positive #32320
Assign an arbitrary property to that object and set it equal to a function that calls the handler from step 2.
Witness the InvalidReact: Ref values (the current property) may not be accessed during render. error
Ex (also in playground link):
exportdefaultfunctionMyApp(){constdivRef=useRef(null);constmyHandler=e=>{alert(divRef.current.innerText);}constanchorProps={};anchorProps.onClick=()=>myHandler();return(<><divref={divRef}>Hello World</div><a{...anchorProps}>What does the div say?</a></>);}
For what ive seen in the documentation the problem is because it doesnt consider the possibility that you can add an onClick property later in the code, which make react think its another property that cannot use the current method of a ref, ill lok at it, post the answer if i find the problem causing it to false positive that
okay, i think i found it, well in the declaration of the function validateNoRefAccessInRenderImpl on react/compliler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoRefAccesInRender.ts we have cases and each case is treated differently, for example, the ObjectMethod dont call any problems, but the problem is, when you call anchorProps.onClick = () => myHandler(); is not calling the ObjectMethod case, but is calling the PropertyStore case, which triggers by basically anything that stores a new property, the problem is this case also includes ComputedStore which is something like this myObject["age"] = 30; which could be interpreted as we are calling the current property in render lets say for example myObject["age"] = divRef and that could get that error, but as im new to this community i call @mofeiZ to take a look at this and tell me if im right
Activity
sushanthi1813 commentedon Feb 8, 2025
You can keep an eye on the React Compiler release notes for updates regarding this issue.
funktr0n commentedon Feb 10, 2025
@sushanthi1813 I'm not seeing any release notes at that link
mofeiZ commentedon Feb 19, 2025
Thanks for the report! We've been working on reducing false positives from
ref.currentvalidation but this one seems to have slipped by.dinge321 commentedon Feb 19, 2025
For what ive seen in the documentation the problem is because it doesnt consider the possibility that you can add an onClick property later in the code, which make react think its another property that cannot use the current method of a ref, ill lok at it, post the answer if i find the problem causing it to false positive that
dinge321 commentedon Feb 20, 2025
okay, i think i found it, well in the declaration of the function validateNoRefAccessInRenderImpl on react/compliler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoRefAccesInRender.ts we have cases and each case is treated differently, for example, the ObjectMethod dont call any problems, but the problem is, when you call anchorProps.onClick = () => myHandler(); is not calling the ObjectMethod case, but is calling the PropertyStore case, which triggers by basically anything that stores a new property, the problem is this case also includes ComputedStore which is something like this myObject["age"] = 30; which could be interpreted as we are calling the current property in render lets say for example myObject["age"] = divRef and that could get that error, but as im new to this community i call @mofeiZ to take a look at this and tell me if im right
josephsavona commentedon Jul 29, 2025
Fix landed in #34026 - thanks again for reporting!