-
Notifications
You must be signed in to change notification settings - Fork 46.8k
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: Controlled state input weird behavior when state update is postponed to the next micro task #31182
Comments
I have run it but haven't encountered any issues with it. |
InvestigationGenerally speaking, React 18 auto batching's mechanism of event handlers is like: function domOnValueChange(e) {
reactComponentOnChange(e); // collect state updates but does not actually performs those updates, not an actual function name
performStateUpdates(); // here the auto batching works, not an actual function name
// some additional codes to maintain DOM node states
restoreControlledState(element, props); // actual function, use latest props value of the corresponding component to update element
} The Suppose this is an Here, if the state is updated in the same micro task, then the Instead, if the state update is postponed to another micro task, then ThoughtsI personally think this issue should be categorized as a wont fix, but maybe someone can offer a solution to make it more sound, I'm not sure. NOTE: In latest React main branch some function name has changed, but their names are pretty similar and it is not difficult to find the corresponding logic. |
React version: v18.3
Steps To Reproduce
Link to code example: https://codesandbox.io/p/sandbox/74mhkd
The current behavior
By adding an additional queueMicrotask to the second input, two inputs behavior are different.
Screen.Recording.2024-10-18.at.10.50.40.mov
The expected behavior
Work loop stuff should not affect DOM manipulation.
Is it a bug or feature? Is it a react stuff?
The text was updated successfully, but these errors were encountered: