-
Notifications
You must be signed in to change notification settings - Fork 49.7k
[Compiler] ValidateNoDerivedComputationsInEffects test cases #34574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
5b75fc9 to
f3172ce
Compare
6cc663d to
9d120ad
Compare
| function Component({propValue}) { | ||
| const [value, setValue] = useState(null); | ||
| useEffect(() => { | ||
| setValue(propValue); | ||
| }, [propValue]); | ||
|
|
||
| return <MockComponent onSet={setValue} />; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, in this case we can't statically suggest a rewrite
|
|
||
| return ( | ||
| <div> | ||
| <input value={name} onChange={e => setName(e.target.value)} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
| useEffect(() => { | ||
| setValue(propValue); | ||
| localFunction(); | ||
| }, [propValue]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're allowing this case because (1) we want to avoid false positives and (2) we don't want to analyze all local functions right(?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah... I do think we should eventually analyze local functions at least the ones within the component, and maybe consider them setStates if they contain a nested setState I think we might want to take a closer look into localFunction now that I think about it
| const [value, setValue] = useState(null); | ||
| useEffect(() => { | ||
| setValue(propValue); | ||
| globalCall(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, in #34578 we remove this error
Summary: This creates the test cases we expect this first iteration of calculate in render to catch The goal is to have tests that will be in a good state once we have the first iteration of the calculate in render validation working, which should be pretty limited in what its capturing. Test Plan: Test cases
…#34580) Summary: Change error and update snapshots The error now mentions what values are causing the issue which should provide better context on how to fix the issue --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34580). * __->__ #34580 * #34579 * #34578 * #34577 * #34575 * #34574
…#34580) Summary: Change error and update snapshots The error now mentions what values are causing the issue which should provide better context on how to fix the issue --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34580). * __->__ #34580 * #34579 * #34578 * #34577 * #34575 * #34574 DiffTrain build for [09056ab](09056ab)
…#34580) Summary: Change error and update snapshots The error now mentions what values are causing the issue which should provide better context on how to fix the issue --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34580). * __->__ #34580 * #34579 * #34578 * #34577 * #34575 * #34574 DiffTrain build for [09056ab](09056ab)
Summary:
This creates the test cases we expect this first iteration of calculate in render to catch
The goal is to have tests that will be in a good state once we have the first iteration of the calculate in render validation working, which should be pretty limited in what its capturing.
Test Plan:
Test cases
Stack created with Sapling. Best reviewed with ReviewStack.