Skip to content

Submit listener exceptions leave isSubmitting stuck true #2468

Open

Description

@henricop

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions