Skip to content

[compiler] Fix setState-in-effect for React.useEffect namespace calls (#35377)#35419

Merged
josephsavona merged 1 commit intofacebook:mainfrom
AntonChesnokov:fix-set-state-in-effect-react-namespace
Feb 4, 2026
Merged

[compiler] Fix setState-in-effect for React.useEffect namespace calls (#35377)#35419
josephsavona merged 1 commit intofacebook:mainfrom
AntonChesnokov:fix-set-state-in-effect-react-namespace

Conversation

@AntonChesnokov
Copy link
Contributor

Summary

Fix react-hooks/set-state-in-effect false negatives when Hooks are called via a namespace import (e.g. import * as React from 'react' and React.useEffect(...)). The validation now checks the MethodCall property (the actual hook function) instead of the receiver object.

Issue: Bug: #35377

How did you test this change?

Added a regression fixture;
Ran tests and verified it reports EffectSetState and matches the expected output.

Screenshot 2025-12-27 at 14 13 38

@meta-cla meta-cla bot added the CLA Signed label Dec 27, 2025
@appellation
Copy link

I was able to confirm that this fixes the issue we were encountering. Thanks!

@AntonChesnokov
Copy link
Contributor Author

@josephsavona @poteto could you please look into this pull request?

…facebook#35377)

ValidateNoSetStateInEffects treats MethodCall.property as the hook callee (so React.useEffect is detected).\n\nAdds a regression fixture for import * as React with React.useState/React.useEffect.
@josephsavona josephsavona force-pushed the fix-set-state-in-effect-react-namespace branch from 4bdc04f to a352ad0 Compare February 4, 2026 15:47
@josephsavona josephsavona merged commit 22a20e1 into facebook:main Feb 4, 2026
17 checks passed
@josephsavona
Copy link
Member

Thanks for the contribution!

github-actions bot pushed a commit that referenced this pull request Feb 4, 2026
…#35377) (#35419)

## Summary
Fix react-hooks/set-state-in-effect false negatives when Hooks are
called via a namespace import (e.g. `import * as React from 'react'` and
`React.useEffect(...))`. The validation now checks the MethodCall
property (the actual hook function) instead of the receiver object.

Issue: Bug: #35377

## How did you test this change?
Added a regression fixture;
Ran tests and verified it reports `EffectSetState` and matches the
expected output.

<img width="461" height="116" alt="Screenshot 2025-12-27 at 14 13 38"
src="https://github.com/user-attachments/assets/fff5aab9-0f2c-40e9-a6a5-b864c3fa6fbd"
/>

DiffTrain build for [22a20e1](22a20e1)
github-actions bot pushed a commit that referenced this pull request Feb 4, 2026
…#35377) (#35419)

## Summary
Fix react-hooks/set-state-in-effect false negatives when Hooks are
called via a namespace import (e.g. `import * as React from 'react'` and
`React.useEffect(...))`. The validation now checks the MethodCall
property (the actual hook function) instead of the receiver object.

Issue: Bug: #35377

## How did you test this change?
Added a regression fixture;
Ran tests and verified it reports `EffectSetState` and matches the
expected output.

<img width="461" height="116" alt="Screenshot 2025-12-27 at 14 13 38"
src="https://github.com/user-attachments/assets/fff5aab9-0f2c-40e9-a6a5-b864c3fa6fbd"
/>

DiffTrain build for [22a20e1](22a20e1)
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.

3 participants