fix: create fieldMeta on async validation for fields with errors - #2056
Conversation
This updates the validateAsync function to have similar logic to validateSync. See TanStack#1691 where this logic was added to validateSync. Fixes TanStack#2033
🦋 Changeset detectedLatest commit: 0868ac1 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 |
📝 WalkthroughWalkthroughThis PR fixes async validation so fields that only receive form-level async errors still get ChangesFix fieldMeta creation during async validation
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: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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. Comment |
|
@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 af28b12
☁️ Nx Cloud last updated this comment at |
# Conflicts: # packages/form-core/tests/FormApi.spec.ts
…d field (#2233) * fix(form-core): guard FormGroupApi.distributeFieldErrors against unmounted field meta FormGroupApi.distributeFieldErrors called setFieldMeta with an updater that unconditionally spread prev, which is undefined when a group validator returns fields errors for a sub-field with no fieldMetaBase entry yet. Apply the same (prev = defaultFieldMeta) guard already used in FormApi's form-level field-error fan-out (see #1706, #2056). Fixes #2231 * chore: add changeset for #2231 --------- Co-authored-by: Corbin Crutchley <git@crutchcorn.dev>
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
🎯 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
pnpm test:pr.🚀 Release Impact
Summary by CodeRabbit
{ fields: ... }async submission errors are converted into the expected field metadata entries.