Skip to content
Source
Sign inSign up
TanStack/form

fix(form-core): apply synchronous validator results in the same update as the change #2447

OpenTarekkharsa(GitHub profile, opens in a new tab)wants to merge 3 commits intoalpha fromrefs/pull/2447/headopened

Showing 9 changed files with 51 additions and 23 deletions (loading 6).

x
0 of 9 viewed, 9 left
5 additions and 0 deletions.changeset/quick-fields-settle.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/form-core': patch
+---
+​
+Apply synchronous validator results in the same update as the change that triggered them. A field with a synchronous change validator (a function or a Standard Schema that validates synchronously) now renders once per keystroke instead of twice. Debounced and asynchronous validators behave as before.
18 additions and 9 deletionspackages/form-core/src/FieldApi/FieldApi.lib.tsModified
View file
@@ -1,11 +1,11 @@
import { batch, createAtom } from '@tanstack/store'
-import { callUpdater, evaluate, getBy } from '../utils.lib'
+import { callUpdater, evaluate, getBy, isPromiseLike } from '../utils.lib'
import {
clearValidationSourceErrorsFromEvent,
isValidationTriggerEnabled,
parseValidationResult,
runFieldMountValidatorPipeline,
- runFieldValidatorPipeline,
+ runFieldValidatorPipelineMaybeSync,
setValidationSourceError,
} from '../validation'
import { runFieldListenerPipeline } from '../listeners.lib'
@@ -784,7 +784,7 @@
* @private
* Runs this field's validation pipeline.
- async _runFieldValidation(
+ _runFieldValidation(
event: 'change' | 'blur' | 'submit',
options?: {