handleSubmit calls onSubmit again while a submit is still pending (since 1.33.1)
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 78/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- react, typescript
- 領域
- frontend
研究方向
報告指出了 @tanstack/form-core 中的 _handleSubmit 和 this.baseStore.state.isSubmitting;首先追蹤 issue 中描述的提前返回和提交嘗試檢查。使用提供的 Node 指令碼針對目前的程式碼重現問題,然後為 onSubmit 尚未完成時的第二次提交新增或更新回歸測試;完成標準是 onSubmit 只呼叫一次,同時保留 #2120 中的重新提交行為。
由索引模型根據 Issue 內容生成。
描述
Describe the bug
Since #2120 ("clear stale onBlur errors on re-submission", released in 1.33.1), handleSubmit skips its !canSubmit early return on every attempt after the first. canSubmit is also false while a submit is in flight, so a second handleSubmit during a pending onSubmit now runs validation and calls onSubmit again. Up to 1.33.0 that second call returned early.
In practice: a double tap on a submit button, or Enter / the keyboard's "go" pressed twice, sends the request twice. We hit it on a sign-in form and a comment composer in React Native, where the keyboard submit bypasses a disabled button.
Your minimal, reproducible example
No sandbox, it needs only @tanstack/form-core in Node:
// npm i @tanstack/[email protected], then: node repro.mjs
import { FormApi } from '@tanstack/form-core';
const pending = [];
const form = new FormApi({
defaultValues: { name: 'Ada' },
onSubmit: () => new Promise((resolve) => pending.push(resolve)),
});
form.mount();
const first = form.handleSubmit();
await new Promise((resolve) => setTimeout(resolve, 0));
console.log('isSubmitting:', form.state.isSubmitting, 'canSubmit:', form.state.canSubmit);
const second = form.handleSubmit();
await new Promise((resolve) => setTimeout(resolve, 0));
console.log('onSubmit calls:', pending.length, '(expected 1)');
pending.forEach((resolve) => resolve());
await Promise.all([first, second]);
Steps to reproduce
- Run the script with
@tanstack/[email protected]:isSubmitting: true canSubmit: false,onSubmit calls: 1. - Run it with
@tanstack/[email protected]: same state,onSubmit calls: 2.
Expected behavior
A handleSubmit that arrives while isSubmitting is true does not call onSubmit again, as before #2120. Keeping the re-submission behaviour #2120 added and also returning early when this.baseStore.state.isSubmitting is true would cover both.
How often does this bug happen?
Every time
Platform
@tanstack/form-core1.33.5 (via@tanstack/react-form1.33.5)- Node 26, and React Native 0.88 / Hermes in the app
TanStack Form adapter
react-form
TanStack Form version
1.33.5
TypeScript version
5.9
Additional context
The change is in _handleSubmit: if (!this.state.canSubmit && ...) { if (this.baseStore.state.submissionAttempts <= 1) { ...; return; } }. We now wrap onSubmit in a single-flight guard on our side.
- 主要語言
- TypeScript
- 星號
- 6.8k
- 分支
- 705
- 平均合併
- 1 天 6 小時
- 30 天內合併 PR
- 12
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
TanStack/form 的其他 Issue
-
[v2] FieldWithValue<T> erases field.name to any instead of string可能已有人在做 @Priyeshshrivastav 於 2 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 79/100
維護者通常 1 天內回覆
-
`isDefaultValue` is wrong when a field-level `defaultValue` is `null`可能已有人在做 @fenet-as 於 25 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆
-
Async validator doesn't re-trigger `isValidating` after first failed validation可能已有人在做 @drewsephski 於 29 天前認領。 未關閉
難度 2/5 1-2 天 新手友好度 72/100
維護者通常 1 天內回覆
-
[v2 alpha] devtools are always light mode可能已有人在做 @dikshit-n 於 64 天前認領。 未關閉area: runtime scope: devtools type: bug v2
難度 2/5 1-3 小時 新手友好度 65/100
維護者通常 1 天內回覆
-
FormGroupApi.getRelatedFields and FieldApi.validate() use unguarded startsWith for group membership, matching unrelated fields with a shared name prefix可能已有人在做 @HDPark95 於 82 天前認領。 未關閉area: runtime scope: core type: bug v1
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆
相似的 Issue
-
bug
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆
-
area:ui bug effort:S priority:P2
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
Typo in WSL project description on Projects page可能已有人在做 @akhil9tiet 今天認領。 未關閉
難度 1/5 1 小時以內 新手友好度 75/100
microsoft/opensource.microsoft.com#1066 · 1 則留言 ·
-
ArcGIS Maps SDK for JavaScript c-carousel calcite-design-tokens enhancement impact - p3 - not time sensitive needs triage
難度 2/5 1-3 小時 新手友好度 68/100
Esri/calcite-design-system#15565 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 68/100
linkwarden/linkwarden#1891 ·
維護者通常 1 天內回覆