Submit listener exceptions leave isSubmitting stuck true

Đang mở Phù hợp với người mới
#2,468 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@henricop đang làm issue này rồi.

Từ ngày 7/11/2026.

  • #2469 của @henricop — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu bằng cách đọc phần triển khai FormApi.handleSubmit() trong form-core và khối xử lý lỗi khi gửi; issue cho biết các lời gọi đồng bộ đến listeners.onSubmit của form và field chạy ngay trước khối đó. Thêm kiểm thử hồi quy cho cả hai trường hợp listener, xác nhận lỗi vẫn bị reject, callback gửi bị bỏ qua và isSubmitting được đặt lại thành false trong khi isSubmitSuccessful vẫn là false. Xác nhận lần gửi thành công sau đó vẫn hoạt động và chạy bộ kiểm thử form-core.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
6.8k
Fork
717
Merge trung bình
5 ngày 22 giờ
Pull request đã merge (30 ngày)
14

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của TanStack/form

Tất cả issue của TanStack/form

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.