-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
Bug: FunctionComponent re-render phase cause a bug #20675
Comments
Thanks for the report.
The codesandbox is using |
I tried it in v17.0.1 and this problem still occurs, because the function |
Test illustrating the current behavior on it('yields inconsistently when triggering state updates during render', () => {
let handleClick;
function Test() {
const [count, setCount] = useState(0);
useEffect(() => {
Scheduler.unstable_yieldValue(`Effect: ${count}`);
}, [count]);
if (count > 0) {
setCount(0);
}
handleClick = () => setCount(2);
return <Text text={`Render: ${count}`} />;
}
ReactNoop.act(() => {
ReactNoop.render(<Test />);
});
expect(Scheduler).toHaveYielded(['Render: 0', 'Effect: 0']);
ReactNoop.act(() => {
handleClick();
});
expect(Scheduler).toHaveYielded(['Render: 0']);
ReactNoop.act(() => {
handleClick();
});
expect(Scheduler).toHaveYielded(['Render: 0', 'Effect: 0']);
ReactNoop.act(() => {
handleClick();
});
expect(Scheduler).toHaveYielded(['Render: 0']);
});
Could you either update the issue or the codesandbox so that we avoid potential confusion when the bug is reported for one version but the repro uses a different one? |
yeah! i have updated the version of React in the codesandbox |
Is the behavior new in some version, or always been like this? |
It always has been™. Tested with a codesandbox using 16.8. |
@careyke Thanks for the repro! This helped a lot identifying the issue. |
You are welcome! i am very happy to do this |
React version:v17.0.1
Steps To Reproduce
There maybe be a bug in following method
Link to the source code:
react/packages/react-reconciler/src/ReactFiberHooks.new.js
Line 1320 in e316f78
Link to code example: https://codesandbox.io/s/reacthooks-fkihz?file=/src/MaybeABug.js
The current behavior
The first time click the button, it will not print the "effect"
But the second click will print the "effect"
the third will not, the fourth will be and so on
The expected behavior
Maybe should always print nothing!
Remarks
The reason for this phenomenon is when component entering re-render phase, the effect object is a big different in updateQueue and Hook object. But i think should be consistent。
In fact, i am not sure if it is a bug, so I look forward to receiving a reply, thanks
The text was updated successfully, but these errors were encountered: