[compiler][e2e] Add rule of react violation fixture#60
Conversation
Greptile OverviewGreptile SummaryAdded new e2e test fixture
Confidence Score: 2/5
Important Files ChangedFile Analysis
|
| const update = ( | ||
| field: 'username' | 'address', | ||
| kind: 'errorMessage' | 'value', | ||
| ) => { |
There was a problem hiding this comment.
syntax: function signature mismatch - the type definition on line 30 declares a third parameter newValue: string, but the implementation doesn't accept it. Either remove newValue from the type or add it to the function parameters.
| const update = ( | |
| field: 'username' | 'address', | |
| kind: 'errorMessage' | 'value', | |
| ) => { | |
| const update = ( | |
| field: 'username' | 'address', | |
| kind: 'errorMessage' | 'value', | |
| newValue: string, | |
| ) => { |
Prompt To Fix With AI
This is a comment left during a code review.
Path: compiler/packages/babel-plugin-react-compiler/src/__tests__/e2e/rule-of-react-violations/inner-mutation-state.e2e.tsx
Line: 48:51
Comment:
**syntax:** function signature mismatch - the type definition on line 30 declares a third parameter `newValue: string`, but the implementation doesn't accept it. Either remove `newValue` from the type or add it to the function parameters.
```suggestion
const update = (
field: 'username' | 'address',
kind: 'errorMessage' | 'value',
newValue: string,
) => {
```
How can I resolve this? If you propose a fix, please make it concise.| if (kind === 'errorMessage') { | ||
| data.errorMessage = `value${count}`; | ||
| } else { | ||
| data.errorMessage = `value${count}`; | ||
| } |
There was a problem hiding this comment.
logic: both branches set data.errorMessage - when kind === 'value', should set data.value instead
| if (kind === 'errorMessage') { | |
| data.errorMessage = `value${count}`; | |
| } else { | |
| data.errorMessage = `value${count}`; | |
| } | |
| if (kind === 'errorMessage') { | |
| data.errorMessage = `value${count}`; | |
| } else { | |
| data.value = `value${count}`; | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: compiler/packages/babel-plugin-react-compiler/src/__tests__/e2e/rule-of-react-violations/inner-mutation-state.e2e.tsx
Line: 58:62
Comment:
**logic:** both branches set `data.errorMessage` - when `kind === 'value'`, should set `data.value` instead
```suggestion
if (kind === 'errorMessage') {
data.errorMessage = `value${count}`;
} else {
data.value = `value${count}`;
}
```
How can I resolve this? If you propose a fix, please make it concise.| } | ||
| return newState; | ||
| }); | ||
| setCount(count + 1); |
There was a problem hiding this comment.
logic: stale closure issue - count value used on line 59/61 will always be the value from when update was created, not the current state. Should use the functional form: setCount(prevCount => prevCount + 1) and access count from the updater, or use count from within the setState callback
Prompt To Fix With AI
This is a comment left during a code review.
Path: compiler/packages/babel-plugin-react-compiler/src/__tests__/e2e/rule-of-react-violations/inner-mutation-state.e2e.tsx
Line: 65:65
Comment:
**logic:** stale closure issue - `count` value used on line 59/61 will always be the value from when `update` was created, not the current state. Should use the functional form: `setCount(prevCount => prevCount + 1)` and access count from the updater, or use `count` from within the setState callback
How can I resolve this? If you propose a fix, please make it concise.
Mirror of facebook/react#31114
Original author: mofeiZ
Stack from ghstack (oldest at bottom):