Skip to content
Source
Sign inSign up
TanStack/form

fix(form-core): clear stale onBlur errors on re-submission #2120

MergedrestareaByWeezy(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/2120/headmerged 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. 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)
      • .changeset/fix-stale-onblur-resubmit.md

      📝 Walkthrough

      Walkthrough

      Updated FormApi._handleSubmit to avoid skipping validation on subsequent submission attempts: when !this.state.canSubmit and 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 stale onBlur errors can be cleared before deciding submission outcome.

      Changes

      Cohort / File(s)Summary
      FormApi Submission Logic
      packages/form-core/src/FormApi.ts
      Changed _handleSubmit early-exit behavior: only the first invalid submit returns early and calls onSubmitInvalid; subsequent submits proceed to re-run field validators and then determine whether to call onSubmit or onSubmitInvalid.
      FormApi Test Coverage
      packages/form-core/tests/FormApi.spec.ts
      Added regression test that verifies onBlur field validators re-run on re-submission and that stale onBlur errors are cleared when field conditions change.
      Release Notes / Changeset
      .changeset/fix-stale-onblur-resubmit.md
      Added a changeset entry describing the patch: "fix(form-core): clear stale onBlur errors on re-submission".

      Sequence 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

      🐰 I hopped upon a submit and learned to try again, Old blur-born errors loosened from their hold, Validators woke and cleared the stain, The form at last could do what’s bold. ✨

      🚥 Pre-merge checks | ✅ 5
      ✅ Passed checks (5 passed)
      Check nameStatusExplanation
      Title check✅ PassedThe title accurately describes the main change: fixing stale onBlur errors being cleared on re-submission, which directly addresses the core issue.
      Description check✅ PassedThe description follows the template structure with all required sections completed: Changes section explains the fix and issue reference, Checklist items are checked, and Release Impact is properly documented with changeset confirmation.
      Linked Issues check✅ PassedThe PR directly addresses issue #2034 by implementing field-level validation re-runs on re-submission to clear stale onBlur errors, matching the expected behavior described in the issue.
      Out of Scope Changes check✅ PassedAll changes are in-scope: FormApi.ts modification fixes the submission logic, FormApi.spec.ts adds a regression test, and the changeset documents the fix—all directly related to resolving issue #2034.
      Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
      ✏️ Tip: You can configure your own custom pre-merge checks in the settings.
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

      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
      Comment `@coderabbitai help` to get the list of available commands and usage tips.
    2. 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.

    3. View your CI Pipeline Execution ↗ for commit bdd4fc05d9ab62e164e98f810b735838035e214e

      CommandStatusDurationResult
      nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded4m 21sView ↗
      nx run-many --target=build --exclude=examples/**✅ Succeeded41sView ↗

      ☁️ Nx Cloud last updated this comment at 2026-07-09 09:26:47 UTC

    4. More templates

      @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@2120

      commit: bdd4fc0

    5. :warning: Please install the 'codecov app svg image' 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.
  • Sign in to join this conversation.