_handleSubmit gates form-level validation behind field-level validity, causing incomplete error reports on submit
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 55/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- react, typescript
- Lĩnh vực
- frontend
Hướng nghiên cứu
Bắt đầu tại _handleSubmit trong React Form adapter và tái hiện hành vi bằng CodeSandbox được liên kết. Theo dõi validateAllFields('submit'), cổng isFieldsValid và validate('submit'); hoàn tất khi quá trình xác thực submit báo cáo lỗi từ cả hai giai đoạn và đường dẫn invalid-submit nhận được kết quả kết hợp.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
I believe this is a bug, though I want to flag upfront that the staging in _handleSubmit seems to be intentional. Regardless I'd like to argue the current behavior still isn't right.
_handleSubmit runs validation in two stages with an early return between them:
await this.validateAllFields('submit') // Stage 1: field-level validators
if (!this.state.isFieldsValid){ /* ... */ return } // Gate
await this.validate('submit') // Stage 2: form-level validators
If Stage 1 fails, users only see the errors from this stage. So any other invalid fields stay silent until these errors are fixed. This contradicts what users intuitively expect from a submit action: check everything and show all errors.
Setting canSubmitWhenInvalid: true also doesn't fix this. The flag gates whether _handleSubmit runs at all, not how validation is staged within it.
My use case:
I only use form-level validation and canSubmitWhenInvalid: true.
Form-level validators write their errors into individual fields' errorMap. But isFieldsValid reads those entries without distinguishing source. So after a failed submit, those form-level errors count as "field-level invalid" on the next attempt — the isFieldsValid gate triggers, form-level validation is skipped, and stale errors stay on screen while new ones never appear.
This mechanism appears to be the underlying cause / relevant for several issues that have been reported separately: #1874, #1663 (see TeChn4K's reproduction there), #2034
PR #2120 in response to #2034 addresses a narrower symptom and doesn't solve the core issue: In #2034 the user has an onBlur validation on a field with conditional validation logic based on another field. The reported issue can be fixed by linking the other field with onBlurListenTo or using canSubmitWhenInvalid: true. The PR does not touch the isFieldsValid gate, so it does not address the problems above.
Your minimal, reproducible example
https://codesandbox.io/p/sandbox/tanstack-form-bug-7yxscz
Steps to reproduce
- Enter a value for field a, leave field b empty
- submit → Field b shows an error since it's empty
- clear field a
- submit again (notice
canSubmitWhenInvalidis set to true) → only field b shows an error even though field a is also empty
Expected behavior
On submit, both stages should run unconditionally and isValid should be evaluated once over the combined result:
await this.validateAllFields('submit')
await this.validate('submit')
if (!this.state.isValid) {
// onSubmitInvalid with the full error picture
return
}
// onSubmit
Why I think this is the right behavior:
- It matches user intuition for submit. Submit is the moment users most need a complete error report. Partial reports force them to fix-submit-fix-submit until they've discovered every problem, which is worse UX than showing everything at once.
- When
canSubmitWhenInvalidisfalse(the default), existing field errors already prevent_handleSubmitfrom running, so this change should have no effect unless there are filed level validators in which case all errors would now surface on submit instead of only the field-level ones, which I'd argue is also the right behavior. It changes behavior for forms that explicitly opt intocanSubmitWhenInvalid: true— where a complete error report on every submit is exactly what you'd expect.
Happy to open a PR if there's a decision on this.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
not relevant
TanStack Form adapter
react-form
TanStack Form version
1.28.0
TypeScript version
No response
Additional context
No response
- Ngôn ngữ chính
- TypeScript
- Star
- 6.8k
- Fork
- 705
- Merge trung bình
- 1 ngày 7 giờ
- Pull request đã merge (30 ngày)
- 13
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của TanStack/form
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
Maintainer thường phản hồi trong vòng 1 ngày
-
`isDefaultValue` is wrong when a field-level `defaultValue` is `null`Có thể đã có người làm @fenet-as đã nhận 23 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
TanStack/form#2427 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Async validator doesn't re-trigger `isValidating` after first failed validationCó thể đã có người làm @drewsephski đã nhận 27 ngày trước. Đang mở
Độ khó 2/5 1-2 ngày Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[v2 alpha] devtools are always light modeCó thể đã có người làm @dikshit-n đã nhận 61 ngày trước. Đang mởarea: runtime scope: devtools type: bug v2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
FormGroupApi.getRelatedFields and FieldApi.validate() use unguarded startsWith for group membership, matching unrelated fields with a shared name prefixCó thể đã có người làm @HDPark95 đã nhận 80 ngày trước. Đang mởarea: runtime scope: core type: bug v1
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
TanStack/form#2337 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của TanStack/form
Issue tương tự
-
bug module:nodes tests
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
rocketride-org/rocketride-server#3020 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
area: dashboard area: tests good first issue size: XS tests
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Read canvas commentsĐang mởenhancement needs-community-review
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
shaharia-lab/slackcli#501 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] Pod detail shows CPU usage ten times too high, and throws on decimal memory suffixesCó thể đã có người làm @RaphaelFakhri đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 11 ngày
-
`package.json`: build tools listed as runtime dependencies, exact pins causing duplicate installsĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
themesberg/flowbite-vue#471 ·