[next.js] `initialFormState` and no fields rendered may cause `state.values` undefined
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- next.js, react, typescript
- Área
- frontend
Línea de trabajo
Empieza por packages/react-form-nextjs/src/createServerValidate.ts, alrededor de la definición de initialFormState, y lee la guía de integración de Next.js App Router. Reproduce el comportamiento con el ejemplo vinculado de tanstack-form-1923 y determina después si debería cambiar la implementación o la documentación. Se considera terminado cuando la configuración documentada ya no hace que state.values sea undefined y el comportamiento esperado queda explicitado.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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).
- Lenguaje dominante
- TypeScript
- Estrellas
- 6.8k
- Forks
- 717
- Merge medio
- 5 d 22 h
- PR fusionados (30 d)
- 14
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de TanStack/form
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
Submit listener exceptions leave isSubmitting stuck truePosiblemente ocupada @henricop la tomó hace 14 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
handleSubmit calls onSubmit again while a submit is still pending (since 1.33.1)Posiblemente ocupada @twotnguyen la tomó hace 14 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
`isDefaultValue` is wrong when a field-level `defaultValue` is `null`Posiblemente ocupada @fenet-as la tomó hace 40 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
TanStack/form#2427 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Async validator doesn't re-trigger `isValidating` after first failed validationPosiblemente ocupada @drewsephski la tomó hace 44 días. Abierto
Dificultad 2/5 1-2 días Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
Todos los issues de TanStack/form
Issues similares
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
lingdojo/kana-dojo#34449 · 1 comentario · 5 reacciones ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
drizzle-team/drizzle-orm#6726 ·
Los mantenedores suelen responder en 2 días
-
bug platform-desktop platform-windows
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
Termix-SSH/Termix#1951 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Grok provider voice list shows 5 of xAI's 28 built-in voicesPosiblemente ocupada @hkjarral la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
hkjarral/AVA-AI-Voice-Agent-for-Asterisk#883 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100