fix(form-core): clear stale onBlur errors on re-submission #2120
main fromrefs/pull/2120/head·merged by crutchcorn(GitHub profile, opens in a new tab) Changes#
Fixes #2034
When a field has an onBlur validator that produces an error, subsequent submit attempts get blocked. The canSubmit check in _handleSubmit returns early before validateAllFields has a chance to re-run and clear the stale error.
This patch skips the early return on re-submission (submissionAttempts > 1) so that validateAllFields actually runs again. First-submission behavior is unchanged.
Added a regression test that reproduces the exact scenario from the issue — conditional field validation with type switching.
Checklist#
- I have followed the steps in the Contributing guide.
- I have tested this code locally with
pnpm test:pr.
Release Impact#
- This change affects published code, and I have generated a changeset.
- This change is docs/CI/dev-only (no release).
Summary by CodeRabbit#
Bug Fixes
- Stale field-level validation errors from prior onBlur validation are now cleared on resubmission; fields are re-validated so subsequent submits reflect current errors.
Tests
- Added a regression test ensuring onBlur validators re-run and stale errors don't block a later successful submit.
Chores
- Prepared a patch release note marking this fix.
- 1
For context: This is actually fixing a nasty bug that cost us an App Review submission cycle. Would love to see a maintainer take a look.
View your CI Pipeline Execution ↗ for commit bdd4fc05d9ab62e164e98f810b735838035e214e
Command Status Duration Result nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded 4m 21s View ↗ nx run-many --target=build --exclude=examples/**✅ Succeeded 41s View ↗
☁️ Nx Cloud last updated this comment at
2026-07-09 09:26:47UTCMore templates
- @tanstack/form-example-angular-array
- @tanstack/form-example-angular-large-form
- @tanstack/form-example-angular-multi-step-wizard
- @tanstack/form-example-angular-simple
- @tanstack/form-example-angular-standard-schema
- @tanstack/form-example-lit-array
- @tanstack/form-example-lit-large-form
- @tanstack/form-example-lit-multi-step-wizard
- @tanstack/form-example-lit-simple
- @tanstack/form-example-lit-standard-schema
- @tanstack/form-example-lit-ui-libraries
- @tanstack/form-example-preact-multi-step-wizard
- @tanstack/form-example-preact-simple
- @tanstack/form-example-react-array
- @tanstack/form-example-react-compiler
- @tanstack/form-example-react-composition
- @tanstack/form-example-react-devtools
- @tanstack/form-example-react-dynamic
- @tanstack/form-example-react-expo
- @tanstack/field-errors-from-form-validators
- @tanstack/form-example-react-large-form
- @tanstack/form-example-react-multi-step-wizard
- @tanstack/form-example-react-next-server-actions
- @tanstack/form-example-react-next-server-actions-zod
- @tanstack/form-example-react-query-integration
- @tanstack/form-example-remix
- @tanstack/form-example-react-simple
- @tanstack/form-example-react-standard-schema
- @tanstack/form-example-react-tanstack-start
- @tanstack/form-example-react-ui-libraries
- @tanstack/form-example-solid-array
- @tanstack/form-example-solid-devtools
- @tanstack/form-example-solid-large-form
- @tanstack/form-example-solid-multi-step-wizard
- @tanstack/form-example-solid-simple
- @tanstack/form-example-solid-standard-schema
- @tanstack/form-example-svelte-array
- @tanstack/form-example-svelte-large-form
- @tanstack/form-example-svelte-multi-step-wizard
- @tanstack/form-example-svelte-simple
- @tanstack/form-example-svelte-standard-schema
- @tanstack/form-example-vue-array
- @tanstack/form-example-vue-multi-step-wizard
- @tanstack/form-example-vue-simple
- @tanstack/form-example-vue-standard-schema
@tanstack/angular-form
npm i https://pkg.pr.new/@tanstack/angular-form@2120@tanstack/form-core
npm i https://pkg.pr.new/@tanstack/form-core@2120@tanstack/form-devtools
npm i https://pkg.pr.new/@tanstack/form-devtools@2120@tanstack/lit-form
npm i https://pkg.pr.new/@tanstack/lit-form@2120@tanstack/preact-form
npm i https://pkg.pr.new/@tanstack/preact-form@2120@tanstack/react-form
npm i https://pkg.pr.new/@tanstack/react-form@2120@tanstack/react-form-devtools
npm i https://pkg.pr.new/@tanstack/react-form-devtools@2120@tanstack/react-form-nextjs
npm i https://pkg.pr.new/@tanstack/react-form-nextjs@2120@tanstack/react-form-remix
npm i https://pkg.pr.new/@tanstack/react-form-remix@2120@tanstack/react-form-start
npm i https://pkg.pr.new/@tanstack/react-form-start@2120@tanstack/solid-form
npm i https://pkg.pr.new/@tanstack/solid-form@2120@tanstack/solid-form-devtools
npm i https://pkg.pr.new/@tanstack/solid-form-devtools@2120@tanstack/svelte-form
npm i https://pkg.pr.new/@tanstack/svelte-form@2120@tanstack/vue-form
npm i https://pkg.pr.new/@tanstack/vue-form@2120commit:
bdd4fc0:warning: Please install the
to ensure uploads and comments are reliably processed by Codecov.
Codecov Report#
:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 89.71%. Comparing base (
6892ed0) to head (bdd4fc0). :warning: Report is 235 commits behind head on main. :exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.Additional details and impacted files
@@ Coverage Diff @@ ## main #2120 +/- ## ========================================== - Coverage 90.35% 89.71% -0.64% ========================================== Files 38 65 +27 Lines 1752 3200 +1448 Branches 444 804 +360 ========================================== + Hits 1583 2871 +1288 - Misses 149 295 +146 - Partials 20 34 +14:umbrella: View full report in Codecov by Harness. :loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
crutchcorn(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
fdf55fab-12d4-486e-bd7f-66c080186cbf📥 Commits
Reviewing files that changed from the base of the PR and between 01ee70b1d20b914f76bd8a015943f1d67886da6b and 5145dec7c1eb814a3b920a4112d64ca791a907b5.
📒 Files selected for processing (1)
.changeset/fix-stale-onblur-resubmit.md✅ Files skipped from review due to trivial changes (1)
📝 Walkthrough
Walkthrough#
Updated
FormApi._handleSubmitto avoid skipping validation on subsequent submission attempts: when!this.state.canSubmitand not forced by_devtoolsSubmissionOverride, the method now returns early only for the first submission attempt. Later attempts continue to re-run field-level validators so staleonBlurerrors can be cleared before deciding submission outcome.Changes#
packages/form-core/src/FormApi.ts_handleSubmitearly-exit behavior: only the first invalid submit returns early and callsonSubmitInvalid; subsequent submits proceed to re-run field validators and then determine whether to callonSubmitoronSubmitInvalid.packages/form-core/tests/FormApi.spec.tsonBlurfield validators re-run on re-submission and that staleonBlurerrors are cleared when field conditions change..changeset/fix-stale-onblur-resubmit.mdSequence Diagram(s)#
mermaid sequenceDiagram participant User participant FormApi participant FieldValidator participant SubmitHandlers User->>FormApi: trigger handleSubmit() FormApi->>FormApi: check state.canSubmit and _devtoolsSubmissionOverride alt first submission and can't submit FormApi->>SubmitHandlers: call onSubmitInvalid() SubmitHandlers-->>User: notify invalid else subsequent submission or can submit FormApi->>FieldValidator: validateAllFields('submit') FieldValidator-->>FormApi: update field errors (clears stale onBlur errors) FormApi->>FormApi: isFieldsValid() alt valid FormApi->>SubmitHandlers: call onSubmit() SubmitHandlers-->>User: submit success else invalid FormApi->>SubmitHandlers: call onSubmitInvalid() SubmitHandlers-->>User: notify invalid end end
Estimated code review effort#
🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem#
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
#2034by implementing field-level validation re-runs on re-submission to clear stale onBlur errors, matching the expected behavior described in the issue.#2034.✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share