[next.js] `initialFormState` and no fields rendered may cause `state.values` undefined
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
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- next.js, react, typescript
- Lĩnh vực
- frontend
Hướng nghiên cứu
Bắt đầu với packages/react-form-nextjs/src/createServerValidate.ts, ở khu vực định nghĩa initialFormState, và đọc hướng dẫn tích hợp Next.js App Router. Tái hiện hành vi bằng ví dụ tanstack-form-1923 được liên kết, sau đó xác định xem nên thay đổi phần triển khai hay tài liệu. Hoàn tất khi thiết lập được ghi trong tài liệu không còn khiến state.values là undefined và hành vi mong đợi được nêu rõ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
Hi! Great library you have here. I've been using it for while now and first time i've come across this.
In the Next.js App Router guide (https://tanstack.com/form/latest/docs/framework/react/guides/ssr#app-router-integration) it recommends to set the initial server state with
import { initialFormState } from '@tanstack/react-form-nextjs'
// inside component:
const [formState, action] = useActionState(someAction, initialFormState)
// ...
const form = useForm({
transform: useTransform((baseForm) => mergeForm(baseForm, formState ?? {}), [formState]),
// ...
but initialFormState as defined has values: undefined (see: https://github.com/TanStack/form/blob/6a5e1c1a4f0f0519705cc5fd15cbe8afb878a42d/packages/react-form-nextjs/src/createServerValidate.ts#L133)
This means that trying to access state.values.<field> will break as values is now undefined. In my case this cropped up trying to use <form.Subscribe>
Your minimal, reproducible example
None, sorry
Steps to reproduce
- Clone https://github.com/MartinCura/tanstack-form-1923
- pnpm i && pnpm run dev
- Go to http://localhost:3000, reload page
Expected behavior
I expect values to always be defined, as should all of the fields in my schema.
The bug is in application code! ...but following the docs' recommendations 🤔, and using initialFormState which introduces the issue.
How often does this bug happen?
Often
Screenshots or Videos
No response
Platform
- Fedora
- Firefox / Zen
TanStack Form adapter
None
TanStack Form version
v1.27.1
TypeScript version
v5.9.3
Additional context
I'm not sure if this is a docs issue instead of any type of bug, i'll leave it up to you!
I'd say the bottom line is not sure why the values should be allowed to be undefined, and thus if either initialFormState should be something that adapts to the form schema, or outright don't recommend it and make the user write it manually, maybe copying the default values (which is more or less the fix i implemented).
- 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
- 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ó 1/5 Dưới một 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
-
Submit listener exceptions leave isSubmitting stuck trueCó thể đã có người làm @henricop đã nhận 14 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ 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
-
handleSubmit calls onSubmit again while a submit is still pending (since 1.33.1)Có thể đã có người làm @twotnguyen đã nhận 14 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/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 40 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 44 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
Tất cả issue của TanStack/form
Issue tương tự
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
lingdojo/kana-dojo#34449 · 1 bình luận · 5 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
drizzle-team/drizzle-orm#6726 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
bug platform-desktop platform-windows
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Termix-SSH/Termix#1951 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Grok provider voice list shows 5 of xAI's 28 built-in voicesCó thể đã có người làm @hkjarral đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
hkjarral/AVA-AI-Voice-Agent-for-Asterisk#883 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100