fix(reset): preserve isValid state when keepIsValid option is used#13173
Merged
bluebill1049 merged 2 commits intoreact-hook-form:masterfrom Dec 8, 2025
Merged
Conversation
bluebill1049
reviewed
Dec 7, 2025
Comment on lines
+185
to
+187
| if (_state.keepIsValid) { | ||
| return; | ||
| } |
Member
There was a problem hiding this comment.
Isn't this going to keep form validity form state being blocked?
Contributor
Author
There was a problem hiding this comment.
Yes, but the blocking only happens when reset is called with { keepIsValid: true }. If a later reset does not use that option, it won’t be blocked and setValid will run normally. I’ve updated the test case to reflect this.
I’m still not entirely sure what the intended behavior of keepIsValid: true should be, since there are no existing test cases or documented examples. Please let me know if my understanding is off.
Member
There was a problem hiding this comment.
sgtm! i will check the pr again.
- Add keepIsValid flag to internal _state to track when isValid should be preserved - Skip validation recalculation in _setValid when keepIsValid is active - Set flag during reset when keepStateOptions.keepIsValid is true - Add test cases for per-call and form-level keepIsValid options
- Update reset test cases to include separate buttons for resetting with and without the keepIsValid option. - Verify form state and validation status after each reset action to ensure correct behavior. - Ensure that the isValid state is preserved or cleared as expected based on the reset options used. Signed-off-by: a28689604 <[email protected]>
d1a791c to
e4fd245
Compare
bluebill1049
approved these changes
Dec 8, 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
I noticed that the keepIsValid reset option wasn’t working correctly. After calling reset, the isValid state should remain preserved when keepIsValid is enabled. Since I couldn’t find any existing examples or test coverage for this behavior, I added two test cases to verify it. Please review and confirm whether these tests reflect the expected behavior.
Changes
I added a
keepIsValidflag tocreateFormControl, which is set only whenkeepStateOptions.keepIsValidis true. When this flag is active, the_setValidfunction (typically triggered after the re-render following areset) will exit early, preventing the valid state from being updated.Type of change
Checklist: