Skip to content

Conversation

@tt-a1i
Copy link

@tt-a1i tt-a1i commented Dec 12, 2025

Summary

  • Fix fields re-rendering twice on each keystroke when there are no async validators
  • Add test case to verify isValidating doesn't toggle unnecessarily

Problem

As reported in #1130, fields were re-rendering twice on each keystroke because isValidating was being set to true then immediately false in validateAsync, even when there were no async validators to run.

Root Cause

In FieldApi.validateAsync:

// Before: Always toggled isValidating regardless of validators
if (!this.state.meta.isValidating) {
  this.setMeta((prev) => ({ ...prev, isValidating: true }))  // Render 1
}
// ... later ...
this.setMeta((prev) => ({ ...prev, isValidating: false }))   // Render 2

Solution

Check if there are actual async validators before toggling isValidating:

const hasAsyncValidators =
  validates.some((v) => v.validate) ||
  linkedFieldValidates.some((v) => v.validate)

if (hasAsyncValidators) {
  // Only toggle isValidating if we have validators to run
}

Test Plan

  • Added test case: should not toggle isValidating when there are no async validators
  • All existing tests pass (404 tests in form-core, 78 tests in react-form)

Fixes #1130

Fields were re-rendering twice on each keystroke because `isValidating`
was being toggled (true -> false) even when there were no async validators.

This fix checks if there are actual async validators before setting
`isValidating` state, preventing unnecessary re-renders.

Fixes TanStack#1130
@changeset-bot
Copy link

changeset-bot bot commented Dec 12, 2025

🦋 Changeset detected

Latest commit: 89c5741

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@tanstack/form-core Patch
@tanstack/angular-form Patch
@tanstack/form-devtools Patch
@tanstack/lit-form Patch
@tanstack/react-form Patch
@tanstack/solid-form Patch
@tanstack/svelte-form Patch
@tanstack/vue-form Patch
@tanstack/react-form-devtools Patch
@tanstack/solid-form-devtools Patch
@tanstack/react-form-nextjs Patch
@tanstack/react-form-remix Patch
@tanstack/react-form-start Patch

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fields re-render twice on each keystroke, based on validation state

1 participant