Skip to content
Source
Sign inSign up
TanStack/form

fix(form-core): ignore aborted async form-level validation results (continues #2350) #2440

OpenAlexRixten(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/2440/headopened

Showing 3 changed files with 47 additions and 0 deletions.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/quiet-forms-ignore-stale.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+"@tanstack/form-core": patch
+---
+​
+Ignore aborted async form-level validation results so a slower previous run cannot overwrite newer form state.
1 addition and 0 deletionspackages/form-core/src/FormApi.tsModified
View file
@@ -2232,6 +2232,7 @@
} catch (e: unknown) {
rawError = e as ValidationError
+ if (controller.signal.aborted) return resolve(undefined)
const { formError, fieldErrors: fieldErrorsFromNormalizeError } =
normalizeError<TFormData>(rawError)
41 additions and 0 deletionspackages/form-core/tests/FormApi.spec.tsModified
View file
@@ -1420,6 +1420,47 @@
+ it('should ignore aborted async form-level validation results', async () => {
+ vi.useFakeTimers()
+​
+ try {
+ const form = new FormApi({
+ defaultValues: {