Skip to content
Source
Sign inSign up
TanStack/form

fix(form-core): prevent concurrent onSubmit while a submission is in progress #2428

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

Showing 3 changed files with 63 additions and 3 deletions.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/fix-concurrent-on-submit.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/form-core': patch
+---
+​
+fix(form-core): prevent concurrent onSubmit invocations while a submission is in progress
10 additions and 3 deletionspackages/form-core/src/FormApi.tsModified
View file
@@ -2443,13 +2443,20 @@
const submitMetaArg =
submitMeta ?? (this.options.onSubmitMeta as TSubmitMeta)
- if (!this.state.canSubmit && !this._devtoolsSubmissionOverride) {
+ if (
+ this.state.isSubmitting ||
+ (!this.state.canSubmit && !this._devtoolsSubmissionOverride)
+ ) {
// On re-submission (submissionAttempts > 1), skip the early return so
// validateAllFields can re-run and clear stale field errors (e.g. from a
// previous onBlur validation that is no longer relevant). The
// isFieldsValid check below will call onSubmitInvalid if the form is
- // still invalid after re-validation.
- if (this.baseStore.state.submissionAttempts <= 1) {
+ // still invalid after re-validation. A submission that is already in
+ // progress always returns early so onSubmit cannot run concurrently.
+ if (
+ this.baseStore.state.submissionAttempts <= 1 ||
+ this.state.isSubmitting
+ ) {
Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)