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 于 63 天前认领。 未关闭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
-
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
"Claude Code request is missing its initial user message" when the prompt starts with an image path未关闭
难度 2/5 1-3 小时 新手友好度 84/100
earendil-works/pi-claude-code#31 ·
维护者通常 8 天内回复
-
bug pending triage
难度 1/5 1 小时以内 新手友好度 92/100
privatenumber/cleye#48 ·
-
Google text documents are base64-encoded twice可能已有人在做 @feiiiiii5 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复