Skip to content
Source
Sign inSign up
TanStack/form

fix(form-core): fix stale async validators from updating isValidating to false #2047

ClosedAdrianLea(GitHub profile, opens in a new tab)wants to merge 3 commits intomain fromrefs/pull/2047/headopened

Showing 1 changed file with 62 additions and 18 deletions.

x
0 of 1 viewed, 1 left
62 additions and 18 deletionspackages/form-core/src/FieldApi.tsModified
View file
@@ -33,6 +33,7 @@
ValidationCause,
ValidationError,
ValidationErrorMap,
+ ValidationErrorMapKeys,
ValidationErrorMapSource,
} from './types'
import type { AsyncValidator, SyncValidator, Updater } from './utils'
@@ -1765,6 +1766,10 @@
const validatesPromises: Promise<ValidationError | undefined>[] = []
const linkedPromises: Promise<ValidationError | undefined>[] = []
+ const fieldControllers = new Map<
+ AnyFieldApi,
+ Map<ValidationErrorMapKeys, AbortController>
+ >()
// Check if there are actual async validators to run before setting isValidating
// This prevents unnecessary re-renders when there are no async validators
@@ -1793,8 +1798,16 @@
fieldValidatorMeta?.lastAbortController.abort()
const controller = new AbortController()
+ if (!fieldControllers.has(field)) {
+ fieldControllers.set(field, new Map())
+ }
+ fieldControllers.get(field)!.set(errorMapKey, controller)
+ if (!fieldControllers.has(field)) {