Submit listener exceptions leave isSubmitting stuck true

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

Maintainer antworten meist innerhalb von 1 Tag

@henricop arbeitet bereits daran.

Seit 07.11.2026.

  • #2469 von @henricop — offen

Bewertung

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

Rechercherichtung

Lies zuerst die Implementierung von FormApi.handleSubmit() in form-core und den Fehlerbehandlungsblock für die Übermittlung; laut Issue werden synchrone Aufrufe von listeners.onSubmit für Formulare und Felder unmittelbar vor diesem Block ausgeführt. Ergänze Regressionstests für beide Listener-Fälle und prüfe dabei, dass der Fehler weiterhin abgelehnt wird, der Submit-Callback übersprungen wird und isSubmitting auf false zurückgesetzt wird, während isSubmitSuccessful false bleibt. Bestätige, dass eine spätere erfolgreiche Übermittlung funktioniert, und führe die form-core-Testsuite aus.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Describe the bug

A synchronous exception in a form-level or field-level listeners.onSubmit rejects form.handleSubmit() but leaves form.state.isSubmitting set to true. The submit callback itself is correctly skipped, but a UI that disables its submit button while submitting stays disabled after the rejected listener.

The form already resets this lifecycle state when the main onSubmit callback throws. The listener calls currently run just before that error-handling block.

Minimal reproduction
import { FormApi } from '@tanstack/form-core'

const form = new FormApi({
  defaultValues: { name: 'Ada' },
  listeners: {
    onSubmit: () => { throw new Error('Submit listener failed') },
  },
})
form.mount()

try {
  await form.handleSubmit()
} catch (error) {
  console.log((error as Error).message) // Submit listener failed
}
console.log(form.state.isSubmitting) // true; expected false

The same result occurs when the throwing listener is attached to a mounted FieldApi instead of the form.

Expected behavior

The original exception should still reject handleSubmit() and prevent the submission callback from running, while isSubmitting returns to false and isSubmitSuccessful stays false. A later successful submission should work normally.

Verification

Reproduced on current main (eba4084, form-core 1.33.5), Node 24.19.0. Two regression tests (form listener and field listener) fail on main because isSubmitting remains true. Moving those synchronous listener calls into the existing submission error-handling block makes both pass; the form-core suite passes 507 tests with 3 existing todo tests and no type errors.

This report and the proposed repair were prepared with Codex assistance and checked locally. The scope is synchronous submit listener exceptions; it does not promise handling of detached asynchronous work started by a listener.

Vorherrschende Sprache
TypeScript
Sterne
6.8k
Forks
717
Ø Merge
5 T. 22 Std.
Gemergte PRs (30 T.)
14

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.