Conversation
…fixture This fixture demonstrates that `@validateNoSetStateInEffects` currently only detects setState calls in `useEffect()` but misses `React.useEffect()`.
The `@validateNoSetStateInEffects` validation now correctly handles both `useEffect()` and `React.useEffect()` patterns.
Greptile OverviewGreptile SummaryFixed a bug where The fix changes line 100 in
Confidence Score: 5/5
Important Files Changed
|
|
This pull request has been automatically marked as stale. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize reviewing it yet. Your contribution is very much appreciated. |
|
Closing this pull request after a prolonged period of inactivity. If this issue is still present in the latest release, please ask for this pull request to be reopened. Thank you! |
Mirror of facebook/react#35280
Original author: jynxio
Summary
I noticed that
React.useEffectbypasses theset-state-in-effectvalidation, as shown below.Initially I thought this was an
eslint-plugin-react-hooksissue, but later realized it's a Compiler-level bug.The bug was in the callee extraction for
MethodCall: it checkedreceiver(theReactnamespace) instead ofproperty(theuseEffectmethod). SinceReactis not an effect hook, the validation was skipped.The fix changes
instr.value.receivertoinstr.value.propertyso thatuseEffectis correctly identified as an effect hook.How did you test this change?
React.useEffectcase toinvalid-setState-in-useEffect.js.invalid-setState-in-useEffect.expect.mdand checked the Logs: only oneCompileErrorat line 7, missingReact.useEffectat line 10. (See Commit 1)ValidateNoSetStateInEffects.ts.invalid-setState-in-useEffect.expect.mdagain and checked the Logs: now twoCompileErrors are reported (line 7 and line 10). (See Commit 2)compiler/packages/babel-plugin-react-compiler(yarn snap:ci).