-
-
Notifications
You must be signed in to change notification settings - Fork 566
Description
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:
| values: undefined, |
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).