Skip to content

Conversation

@tt-a1i
Copy link
Contributor

@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: e77c124

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

ccrutchley-ih

This comment was marked as spam.

Copy link
Member

@crutchcorn crutchcorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for this!

@nx-cloud
Copy link

nx-cloud bot commented Dec 15, 2025

View your CI Pipeline Execution ↗ for commit e77c124

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 1m 36s View ↗
nx run-many --target=build --exclude=examples/** ✅ Succeeded 32s View ↗

☁️ Nx Cloud last updated this comment at 2025-12-15 11:39:00 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 15, 2025

More templates

@tanstack/angular-form

npm i https://pkg.pr.new/@tanstack/angular-form@1929

@tanstack/form-core

npm i https://pkg.pr.new/@tanstack/form-core@1929

@tanstack/form-devtools

npm i https://pkg.pr.new/@tanstack/form-devtools@1929

@tanstack/lit-form

npm i https://pkg.pr.new/@tanstack/lit-form@1929

@tanstack/react-form

npm i https://pkg.pr.new/@tanstack/react-form@1929

@tanstack/react-form-devtools

npm i https://pkg.pr.new/@tanstack/react-form-devtools@1929

@tanstack/react-form-nextjs

npm i https://pkg.pr.new/@tanstack/react-form-nextjs@1929

@tanstack/react-form-remix

npm i https://pkg.pr.new/@tanstack/react-form-remix@1929

@tanstack/react-form-start

npm i https://pkg.pr.new/@tanstack/react-form-start@1929

@tanstack/solid-form

npm i https://pkg.pr.new/@tanstack/solid-form@1929

@tanstack/solid-form-devtools

npm i https://pkg.pr.new/@tanstack/solid-form-devtools@1929

@tanstack/svelte-form

npm i https://pkg.pr.new/@tanstack/svelte-form@1929

@tanstack/vue-form

npm i https://pkg.pr.new/@tanstack/vue-form@1929

commit: e77c124

@codecov
Copy link

codecov bot commented Dec 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.74%. Comparing base (6892ed0) to head (e77c124).
⚠️ Report is 96 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1929      +/-   ##
==========================================
- Coverage   90.35%   89.74%   -0.61%     
==========================================
  Files          38       48      +10     
  Lines        1752     1931     +179     
  Branches      444      483      +39     
==========================================
+ Hits         1583     1733     +150     
- Misses        149      177      +28     
- Partials       20       21       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@crutchcorn crutchcorn merged commit c753d5e into TanStack:main Dec 15, 2025
7 checks passed
@github-actions github-actions bot mentioned this pull request Dec 15, 2025
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

3 participants