handleSubmit calls onSubmit again while a submit is still pending (since 1.33.1)
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
- Run the script with
@tanstack/[email protected]:isSubmitting: true canSubmit: false,onSubmit calls: 1. - 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-core1.33.5 (via@tanstack/react-form1.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
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus TanStack/form
-
[v2] FieldWithValue<T> erases field.name to any instead of stringEvtl. vergeben @Priyeshshrivastav hat das vor 2 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 79/100
TanStack/form#2465 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
`isDefaultValue` is wrong when a field-level `defaultValue` is `null`Evtl. vergeben @fenet-as hat das vor 25 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
TanStack/form#2427 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Async validator doesn't re-trigger `isValidating` after first failed validationEvtl. vergeben @drewsephski hat das vor 29 Tagen übernommen. Offen
Schwierigkeit 2/5 1-2 Tage Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
[v2 alpha] devtools are always light modeEvtl. vergeben @dikshit-n hat das vor 63 Tagen übernommen. Offenarea: runtime scope: devtools type: bug v2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
Maintainer antworten meist innerhalb von 1 Tag
-
FormGroupApi.getRelatedFields and FieldApi.validate() use unguarded startsWith for group membership, matching unrelated fields with a shared name prefixEvtl. vergeben @HDPark95 hat das vor 82 Tagen übernommen. Offenarea: runtime scope: core type: bug v1
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
TanStack/form#2337 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
Ähnliche Issues
-
JSDelivr CDN is brokenOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
-
🐛 bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
LibreChat-AI/LibreChat#17875 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
Maintainer antworten meist innerhalb von 1 Tag
-
category:helper tech-debt
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
LanternOps/breeze#11285 ·
Maintainer antworten meist innerhalb von 1 Tag
-
area: core area: docs good first issue help wanted lane: free-agent priority: P3 roadmap size: XS type: task
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 86/100
arminazimi/seaworthy#701 ·
Maintainer antworten meist innerhalb von 1 Tag