fix(form-core): clear stale onBlur errors on re-submission#2120
fix(form-core): clear stale onBlur errors on re-submission#2120restareaByWeezy wants to merge 2 commits intoTanStack:mainfrom
Conversation
…errors When a field has an onBlur validator that produces an error, subsequent form submission attempts are blocked by a canSubmit check that runs before validateAllFields. This means stale onBlur errors (e.g. from a field that is no longer invalid) prevent re-submission. Fix: on re-submission attempts (submissionAttempts > 1), skip the early canSubmit return so validateAllFields can re-run all field validators for the submit cause. Stale errors are cleared and the isFieldsValid check below handles the invalidity gate correctly. First-submission behavior (submissionAttempts <= 1) is unchanged so existing canSubmit semantics (e.g. onMount errors) are preserved. Fixes TanStack#2034
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughUpdated Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
Changes
Fixes #2034
When a field has an
onBlurvalidator that produces an error, subsequent submit attempts get blocked. ThecanSubmitcheck in_handleSubmitreturns early beforevalidateAllFieldshas a chance to re-run and clear the stale error.This patch skips the early return on re-submission (
submissionAttempts > 1) so thatvalidateAllFieldsactually 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
pnpm test:pr.Release Impact
Summary by CodeRabbit
Bug Fixes
Tests
Chores