fix(validation): batch isValidating state updates with validation result#13181
Merged
bluebill1049 merged 4 commits intoreact-hook-form:masterfrom Dec 7, 2025
Merged
Conversation
d3554cd to
9188b98
Compare
Previously, _runSchema called _updateIsValidating() internally after awaiting the resolver, which prevented batching with subsequent state updates. Moving this call to each caller enables better batching and reduces unnecessary re-renders. Signed-off-by: a28689604 <[email protected]>
9188b98 to
9bab13c
Compare
bluebill1049
approved these changes
Dec 7, 2025
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
Sign up for free
to 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.
Proposed Changes
Issue #13156 reports an unexpected transition in
formState.isValidatingwhen using a resolver. During validation,isValidatingbriefly flips fromtruetofalsebefore the resolver has finished updatingerrors, which makes the form temporarily look valid even though validation hasn’t finished yet.After investigating, the cause is that the current implementation updates
isValidatinginside an async function containing anawait, which breaks React’s state batching. As a result, theisValidating: falseupdate is emitted separately from the subsequenterrorsand other updates.Relevant code:
react-hook-form/src/logic/createFormControl.ts
Lines 435 to 449 in 1536f7c
Because the second
_updateIsValidatingruns after an awaited promise, React flushes it independently, creating an intermediate inconsistent state:isValidating === falseerrors[field] === undefinedThis is exactly what the reproduction shows.
Changes
To ensure
isValidating: falseis batched together with the resolver result and the following state updates, the call to_updateIsValidating(name)has been moved out of_runSchemaand placed immediately after the await_runSchema(...)call.This guarantees the state transition occurs in the same flush as the resolver output, preventing the temporary invalid intermediate state.
Type of change
fixes: #13156
Checklist: