Submit listener exceptions leave isSubmitting stuck true

未關閉 適合新手
#2,468 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@henricop 已經在處理了。

開始於 2026年11月7日。

  • #2469 來自 @henricop —— 未關閉

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
72/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
typescript
領域
backend

研究方向

先閱讀 form-core 中 FormApi.handleSubmit() 的實作及其提交錯誤處理區塊;issue 指出,表單和欄位對 listeners.onSubmit 的同步呼叫就在該區塊之前執行。為這兩種 listener 情況新增迴歸測試,檢查錯誤仍會被拒絕、提交回呼會被略過,且 isSubmitting 會重設為 false,而 isSubmitSuccessful 維持 false。確認之後的成功提交可以正常運作,並執行 form-core 測試套件。

由索引模型根據 Issue 內容生成。

描述

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.

主要語言
TypeScript
星號
6.8k
分支
717
平均合併
5 天 22 小時
30 天內合併 PR
14

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

TanStack/form 的其他 Issue

查看 TanStack/form 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。