Skip to content
Source
Sign inSign up
TanStack/form

fix(form-core): set isValidating on every async validation run #2423

Opendrewsephski(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/2423/headopened

🎯 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 run in packages/form-core: 18 files, 506 tests pass
  • pnpm test:pr (nx affected vs main): 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. 🦋 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
      NameType
      @tanstack/form-corePatch
      @tanstack/angular-formPatch
      @tanstack/form-devtoolsPatch
      @tanstack/lit-formPatch
      @tanstack/preact-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 in Change Stack →

      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.md
      • packages/form-core/src/FieldApi.ts
      • packages/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 isValidating and 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.md
      validateAsync clears 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 the isValidating behavior 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 945f8

      No merge-blocking issue is identified for the async-validation state fix.

      🚥 Pre-merge checks | ✅ 5
      ✅ Passed checks (5 passed)
      Check nameStatusExplanation
      Title check✅ PassedThe title clearly and concisely describes the primary fix: setting isValidating during every asynchronous validation run.
      Description check✅ PassedThe description includes the change, motivation, root cause, implementation details, test results, checklist, and changeset information. It satisfies the repository template.
      Linked Issues check✅ PassedIssue #2372 requires field().state.meta.isValidating to become true during each later async validation and to preserve the validator result. FieldApi.validateAsync now clears the validation time…
      Out of Scope Changes check✅ PassedThe 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✅ PassedNo 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.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.

Sign in to join this conversation.