fix: create fieldMeta on async validation for fields with errors #2056
main fromrefs/pull/2056/head·merged 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.
- Added coverage to verify
- 1
📝 Walkthrough
Walkthrough#
This PR fixes async validation so fields that only receive form-level async errors still get
fieldMetacreated. 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.mdvalidateAsyncnow processes field names from both existingfieldMetakeys andfieldErrorsFromFormValidators, skips only when neither meta nor errors exist, and initializes missing meta fromdefaultFieldMetabefore merging error maps. A changeset entry records the patch release note.Test async form submit validation fieldMeta creation
packages/form-core/tests/FormApi.spec.tsNew async submit-validation test verifies a { fields: ... }error result createsfieldMeta.ageand setserrorMap.onSubmitafterhandleSubmit()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.onSubmitSuggested reviewers:
crutchcorn🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation Linked Issues check ✅ Passed The PR directly addresses issue #2033by implementing the expected behavior where async validation creates fieldMeta for affected fields, matching synchronous validation behavior.Out of Scope Changes check ✅ Passed All 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 ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Title check ✅ Passed The title clearly matches the main change: creating fieldMeta during async validation for fields with errors. Description check ✅ Passed The 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.
Comment `@coderabbitai help` to get the list of available commands.@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.
View your CI Pipeline Execution ↗ for commit af28b126e6d4eb60a08625dad618c910a2759d3a
Command Status Duration Result nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded 3m 18s View ↗ nx run-many --target=build --exclude=examples/**✅ Succeeded 40s View ↗
☁️ Nx Cloud last updated this comment at
2026-07-09 09:53:20UTCMore 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@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@2056commit:
1fd754f: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.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.
crutchcorn(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
🦋 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
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