Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork1.2k
Ensure form state is up to date when using uncontrolled components#3790
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
+7 −1
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
vercelbot commentedSep 12, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
The latest updates on your projects. Learn more aboutVercel for GitHub.
|
philipp-spiess approved these changesSep 12, 2025
987bfa3
intomain 8 checks passed
Uh oh!
There was an error while loading.Please reload this page.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading.Please reload this page.
This PR fixes an issue where uncontrolled
Switch
orCheckbox
components' form state aren't always up to date when calling theonChange
handler.This is because the
onChange
handler is called at the same time the internal state is updated. That means that if you submit the nearest form as part of theonChange
handler that the form state is not up to date yet.We fix this by calling
flushSync()
before we call theonChange
handler when dealing with an uncontrolled component.Test plan
Setup a small reproduction with both a controlled and uncontrolled checkbox
Reproduction
Before:
Notice that the moment I click the
uncontrolled
checkbox, the form is not up to date yet. Pressing submit again shows the correct value even though visually nothing changed anymore.Screen.Recording.2025-09-12.at.14.57.01.mov
After:
Here the form state is always up to date when submitting as part of the
onChange
handler.Screen.Recording.2025-09-12.at.14.57.34.mov
Fixes:#3760