Skip to content
Source
Sign inSign up
TanStack/form

fix: create fieldMeta on async validation for fields with errors #2056

Mergedliteralpie(GitHub profile, opens in a new tab)merged 5 commits intomain fromrefs/pull/2056/headmerged by crutchcorn(GitHub profile, opens in a new tab)

🎯 Changes

This updates the validateAsync function to have similar logic to validateSync. See #1691 where this logic was added to validateSync.

This makes it so that if async validation results in errors, any fields with errors will have a fieldMeta created

Fixes #2033

✅ 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
    • Fixed async validation so field metadata is created/updated for fields that have errors returned from async form validation, even when metadata wasn’t previously initialized.
    • Improved how per-field async validation merges error information, ensuring error messages are correctly reflected in field-level metadata.
  • Tests
    • Added coverage to verify { fields: ... } async submission errors are converted into the expected field metadata entries.
    1. 🦋 Changeset detected

      Latest commit: 0868ac150e1d06531e9b359dd6c2b66a9e9195d3

      The changes in this PR will be included in the next version bump.

      This PR includes changesets to release 13 packages
      NameType
      @tanstack/form-corePatch
      @tanstack/angular-formPatch
      @tanstack/form-devtoolsPatch
      @tanstack/lit-formPatch
      @tanstack/react-formPatch
      @tanstack/solid-formPatch
      @tanstack/svelte-formPatch
      @tanstack/vue-formPatch
      @tanstack/react-form-devtoolsPatch
      @tanstack/solid-form-devtoolsPatch
      @tanstack/react-form-nextjsPatch
      @tanstack/react-form-remixPatch
      @tanstack/react-form-startPatch

      Not sure what this means? Click here to learn what changesets are.

      Click here if you're a maintainer who wants to add another changeset to this PR

    2. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Review Change Stack

      📝 Walkthrough

      Walkthrough

      This PR fixes async validation so fields that only receive form-level async errors still get fieldMeta created. It also adds a test covering submit-time async validation output shaped as { fields: ... }.

      Changes

      Fix fieldMeta creation during async validation

      Layer / File(s)Summary
      Async validation field meta initialization
      packages/form-core/src/FormApi.ts, .changeset/shy-otters-give.md
      validateAsync now processes field names from both existing fieldMeta keys and fieldErrorsFromFormValidators, skips only when neither meta nor errors exist, and initializes missing meta from defaultFieldMeta before merging error maps. A changeset entry records the patch release note.
      Test async form submit validation fieldMeta creation
      packages/form-core/tests/FormApi.spec.ts
      New async submit-validation test verifies a { fields: ... } error result creates fieldMeta.age and sets errorMap.onSubmit after handleSubmit() and timer advancement.

      Estimated code review effort: 3 (Moderate) | ~20 minutes

      Sequence Diagram(s)

      sequenceDiagram
        participant FormApi
        participant onSubmitAsync
        participant fieldMeta
      
        FormApi->>onSubmitAsync: run async submit validation
        onSubmitAsync-->>FormApi: return { fields: { age: error } }
        FormApi->>FormApi: include fieldErrorsFromFormValidators in field list
        FormApi->>fieldMeta: create/update age meta with errorMap.onSubmit

      Suggested reviewers: crutchcorn

      🚥 Pre-merge checks | ✅ 5
      ✅ Passed checks (5 passed)
      Check nameStatusExplanation
      Linked Issues check✅ PassedThe PR directly addresses issue #2033 by implementing the expected behavior where async validation creates fieldMeta for affected fields, matching synchronous validation behavior.
      Out of Scope Changes check✅ PassedAll changes are scoped to the async validation fix: a changeset entry, FormApi.ts logic updates, and corresponding test coverage with no unrelated modifications.
      Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
      Title check✅ PassedThe title clearly matches the main change: creating fieldMeta during async validation for fields with errors.
      Description check✅ PassedThe description follows the template with Changes, Checklist, and Release Impact sections filled in.
      ✨ 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.
    3. literalpie(GitHub profile, opens in a new tab)commented

      @crutchcorn I hate to be the guy who pings the OSS maintainer, but I really think this fix is worth getting merged. We've been using a patch of this change for a few months in our large app without issue. Please let me know if there's anything I can do to help.

      Based on reactions and commit references on this PR and the issue, I think it would benefit others too.

    4. nx-cloud[bot](GitHub profile, opens in a new tab)commented

      View your CI Pipeline Execution ↗ for commit af28b126e6d4eb60a08625dad618c910a2759d3a

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

      ☁️ Nx Cloud last updated this comment at 2026-07-09 09:53:20 UTC

    5. pkg-pr-new[bot](GitHub profile, opens in a new tab)commented
      More templates

      @tanstack/angular-form

      npm i https://pkg.pr.new/@tanstack/angular-form@2056

      @tanstack/form-core

      npm i https://pkg.pr.new/@tanstack/form-core@2056

      @tanstack/form-devtools

      npm i https://pkg.pr.new/@tanstack/form-devtools@2056

      @tanstack/lit-form

      npm i https://pkg.pr.new/@tanstack/lit-form@2056

      @tanstack/preact-form

      npm i https://pkg.pr.new/@tanstack/preact-form@2056

      @tanstack/react-form

      npm i https://pkg.pr.new/@tanstack/react-form@2056

      @tanstack/react-form-devtools

      npm i https://pkg.pr.new/@tanstack/react-form-devtools@2056

      @tanstack/react-form-nextjs

      npm i https://pkg.pr.new/@tanstack/react-form-nextjs@2056

      @tanstack/react-form-remix

      npm i https://pkg.pr.new/@tanstack/react-form-remix@2056

      @tanstack/react-form-start

      npm i https://pkg.pr.new/@tanstack/react-form-start@2056

      @tanstack/solid-form

      npm i https://pkg.pr.new/@tanstack/solid-form@2056

      @tanstack/solid-form-devtools

      npm i https://pkg.pr.new/@tanstack/solid-form-devtools@2056

      @tanstack/svelte-form

      npm i https://pkg.pr.new/@tanstack/svelte-form@2056

      @tanstack/vue-form

      npm i https://pkg.pr.new/@tanstack/vue-form@2056

      commit: 1fd754f

    6. :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.72%. Comparing base (6892ed0) to head (1fd754f). :warning: Report is 247 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    #2056      +/-   ##
      ==========================================
      - Coverage   90.35%   89.72%   -0.63%     
      ==========================================
        Files          38       65      +27     
        Lines        1752     3203    +1451     
        Branches      444      809     +365     
      ==========================================
      + Hits         1583     2874    +1291     
      - 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.