Submit listener exceptions leave isSubmitting stuck true

Aperta Adatta ai principianti
#2,468 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@henricop ci sta già lavorando.

Dal 7/11/2026.

  • #2469 di @henricop — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
backend

Direzione di ricerca

Inizia leggendo l’implementazione di FormApi.handleSubmit() in form-core e il relativo blocco di gestione degli errori di invio; l’issue dice che le chiamate sincrone a listeners.onSubmit del modulo e dei campi vengono eseguite subito prima di quel blocco. Aggiungi test di regressione per entrambi i casi del listener e verifica che l’errore continui a essere rifiutato, che la callback di invio venga saltata e che isSubmitting torni a false mentre isSubmitSuccessful resti false. Conferma che un invio successivo riesca ed esegui la suite di test di form-core.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
TypeScript
Stelle
6.8k
Fork
717
Merge medio
5g 22h
PR unite (30g)
14

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TanStack/form

Tutte le issue di TanStack/form

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.