handleSubmit calls onSubmit again while a submit is still pending (since 1.33.1)

Offen Anfängerfreundlich
#2,467 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
78/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
react, typescript
Bereich
frontend

Rechercherichtung

Der Bericht verweist auf _handleSubmit und this.baseStore.state.isSubmitting in @tanstack/form-core; beginne damit, den frühen Rücksprung und die im Issue beschriebene Prüfung des Submission-Versuchs nachzuverfolgen. Reproduziere das Problem mit dem bereitgestellten Node-Skript gegen den aktuellen Code und füge anschließend einen Regressionstest für ein zweites Submit während eines noch laufenden onSubmit hinzu oder aktualisiere ihn; als erledigt gilt die Aufgabe, wenn onSubmit nur einmal aufgerufen wird und das erneute Submit-Verhalten aus #2120 erhalten bleibt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Describe the bug

Since #2120 ("clear stale onBlur errors on re-submission", released in 1.33.1), handleSubmit skips its !canSubmit early return on every attempt after the first. canSubmit is also false while a submit is in flight, so a second handleSubmit during a pending onSubmit now runs validation and calls onSubmit again. Up to 1.33.0 that second call returned early.

In practice: a double tap on a submit button, or Enter / the keyboard's "go" pressed twice, sends the request twice. We hit it on a sign-in form and a comment composer in React Native, where the keyboard submit bypasses a disabled button.

Your minimal, reproducible example

No sandbox, it needs only @tanstack/form-core in Node:

// npm i @tanstack/[email protected], then: node repro.mjs
import { FormApi } from '@tanstack/form-core';

const pending = [];
const form = new FormApi({
  defaultValues: { name: 'Ada' },
  onSubmit: () => new Promise((resolve) => pending.push(resolve)),
});
form.mount();

const first = form.handleSubmit();
await new Promise((resolve) => setTimeout(resolve, 0));
console.log('isSubmitting:', form.state.isSubmitting, 'canSubmit:', form.state.canSubmit);

const second = form.handleSubmit();
await new Promise((resolve) => setTimeout(resolve, 0));

console.log('onSubmit calls:', pending.length, '(expected 1)');
pending.forEach((resolve) => resolve());
await Promise.all([first, second]);
Steps to reproduce
  1. Run the script with @tanstack/[email protected]: isSubmitting: true canSubmit: false, onSubmit calls: 1.
  2. Run it with @tanstack/[email protected]: same state, onSubmit calls: 2.
Expected behavior

A handleSubmit that arrives while isSubmitting is true does not call onSubmit again, as before #2120. Keeping the re-submission behaviour #2120 added and also returning early when this.baseStore.state.isSubmitting is true would cover both.

How often does this bug happen?

Every time

Platform
  • @tanstack/form-core 1.33.5 (via @tanstack/react-form 1.33.5)
  • Node 26, and React Native 0.88 / Hermes in the app
TanStack Form adapter

react-form

TanStack Form version

1.33.5

TypeScript version

5.9

Additional context

The change is in _handleSubmit: if (!this.state.canSubmit && ...) { if (this.baseStore.state.submissionAttempts <= 1) { ...; return; } }. We now wrap onSubmit in a single-flight guard on our side.

Vorherrschende Sprache
TypeScript
Sterne
6.8k
Forks
705
Ø Merge
1 T. 6 Std.
Gemergte PRs (30 T.)
12

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus TanStack/form

Alle Issues in TanStack/form

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.