Skip to content

fix: ignore stale built-in validation result after reset in handleSubmit - #13761

Merged
bluebill1049 merged 2 commits into
react-hook-form:masterfrom
soroush5:fix/handlesubmit-stale-builtin-after-reset
Sep 19, 2026
Merged

bluebill1049 merged 2 commits into
react-hook-form:masterfrom
soroush5:fix/handlesubmit-stale-builtin-after-reset

Conversation

@soroush5

Copy link
Copy Markdown
Contributor

If reset() runs while handleSubmit awaits an async field validate, the late result still landed as a stale error or a stale onValid call. The in-flight result is now discarded once a reset happened, same guard style as #13733.

Verified: 2 new tests fail before and pass after, full suite green.

Fixes #13760

@bluebill1049

Copy link
Copy Markdown
Member

I think there’s still a stale validation case here with form-level props.validate.

executeBuiltInValidation calls validateForm() before the new shouldAbort check, and validateForm() can call setError / clearErrors after async validation resolves.

So if reset() happens while props.validate is pending, the validation result could still write stale errors after the reset, even though onValid / onInvalid are correctly skipped.

Could we also cover the form-level async validate case and make sure we abort before applying its result?

@soroush5

Copy link
Copy Markdown
Contributor Author

Good catch, you are right. Pushed a follow-up: shouldAbort is now threaded into validateForm too, so a late props.validate result after reset no longer touches errors. Added a form-level regression test (fails before, passes after), full suite green.

@bluebill1049

Copy link
Copy Markdown
Member

nice, could you resolve the conflicts?

@soroush5
soroush5 force-pushed the fix/handlesubmit-stale-builtin-after-reset branch from b6ce545 to 42268f6 Compare September 19, 2026 05:09
@soroush5

Copy link
Copy Markdown
Contributor Author

Rebased and reworked on the new architecture: the guard now lives inside executeBuiltInValidation right after each validateField, so a late field result after reset never reaches formState.errors either. Verified the gap first: the 3 regression tests fail on current master (stale onInvalid still fires), all green with this fix, full suite 1396 passed.

@bluebill1049
bluebill1049 merged commit 551fbe9 into react-hook-form:master Sep 19, 2026
6 checks passed
@soroush5

Copy link
Copy Markdown
Contributor Author

Thanks for merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

handleSubmit ignores reset() during async validation

2 participants