fix(form-core): set isValidating on every async validation run #2423
main fromrefs/pull/2423/head·opened 🎯 Changes#
Fixes #2372.
isValidating is only set for the first async validation run. Every later run reads false while the validator is still pending.
Root cause: validateAsync stores the debounce timer id in field.timeoutIds.validations[cause] and never clears it after the timer fires. The next run sees that id, treats it as a still-pending debounce, and calls endValidation() to compensate. That run already ended on its own, so the counter drops from 1 to 0 right after startValidation().
Change: clear the slot when the timer fires. The compensation now only runs for a timer that was cleared before it fired.
Before, on main, the new test fails on the second run:
FAIL tests/FieldApi.spec.ts > field api > should set isValidating on every async validation run
AssertionError: expected false to be true
❯ tests/FieldApi.spec.ts:929:42
929| expect(field.getMeta().isValidating).toBe(true)
After:
pnpm exec vitest runinpackages/form-core: 18 files, 506 tests passpnpm test:pr(nx affected vsmain): pass, 145 tasks across 58 projects
I also checked two cases locally that are not in the test: a run superseded during its debounce still settles to isValidating: false, and a second run started while the first validator is in flight stays true until it resolves. Both end with _pendingValidationsCount at 0.
✅ Checklist#
- I have followed the steps in the Contributing guide.
- I have tested code changes locally with
pnpm test:pr, or these tests do not apply to this pull request. - I fully understand the code in this pull request, including any code generated with AI assistance.
🚀 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
- Async field validation now reports its validating status during every run and clears it when validation completes.
- Debounced validation no longer leaves a stale timer after the timer fires.
- Validation errors update correctly when field values change.
- 1
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
- Configuration used: Repository: TanStack/form/.coderabbit.yaml
- Review profile: CHILL
- Plan: Advanced
- Run ID:
1c07e24e-9861-41be-8491-b48147eaea63
📥 Commits
Reviewing files that changed from the base of the PR and between 2216fdedf0a5ff17e4ef8567e1321442639b96ca and 945f8461cae43b6069c57fd9c06c26025db91372.
📒 Files selected for processing (3)
.changeset/quiet-fields-revalidate.mdpackages/form-core/src/FieldApi.tspackages/form-core/tests/FieldApi.spec.ts
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
📝 Walkthrough
Walkthrough#
The async field-validation path now clears its debounce timeout slot when the timer fires. A regression test checks
isValidatingand validation errors across two successive values. A patch changeset describes the validation-state behavior.Changes#
Async field validation
Layer / File(s) Summary Async validation run and regression coverage
packages/form-core/src/FieldApi.ts,packages/form-core/tests/FieldApi.spec.ts,.changeset/quiet-fields-revalidate.mdvalidateAsyncclears the validation timeout slot when its debounce timer fires. The regression test checks pending and completed state and validation errors for two successive values. The changeset describes theisValidatingbehavior for async field validation.Priority: ⬇️ Low
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Low
Merge Risk: ⚪ Minimal · up to
945f8No merge-blocking issue is identified for the async-validation state fix.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation Title check ✅ Passed The title clearly and concisely describes the primary fix: setting isValidating during every asynchronous validation run. Description check ✅ Passed The description includes the change, motivation, root cause, implementation details, test results, checklist, and changeset information. It satisfies the repository template. Linked Issues check ✅ Passed Issue #2372requiresfield().state.meta.isValidatingto becometrueduring each later async validation and to preserve the validator result.FieldApi.validateAsyncnow clears the validation time…Out of Scope Changes check ✅ Passed The source change fixes the stale async-validation timer state. The added regression test verifies the linked behavior. The patch changeset documents the published behavior change. These changes suppo… Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2… ✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create a new PR
- Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.drewsephski(GitHub profile, opens in a new tab) linked this to fix #2372
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: 945f8461cae43b6069c57fd9c06c26025db91372
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 14 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