[next.js] `initialFormState` and no fields rendered may cause `state.values` undefined
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 35/100
- Tipo de issue
- Bug
- Clareza
- Razoavelmente clara
- Status de atividade
- Estagnada
- Stack de tecnologia
- next.js, react, typescript
- Domínio
- frontend
Direção de pesquisa
Comece por packages/react-form-nextjs/src/createServerValidate.ts, na região da definição de initialFormState, e leia o guia de integração do Next.js App Router. Reproduza o comportamento usando o exemplo vinculado de tanstack-form-1923 e, em seguida, determine se a implementação ou a documentação deve ser alterada. Considera-se concluído quando a configuração documentada não fizer mais com que state.values seja undefined e o comportamento esperado estiver explícito.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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).
- Linguagem predominante
- TypeScript
- Estrelas
- 6.8k
- Forks
- 717
- Merge médio
- 5d 22h
- PRs com merge (30d)
- 14
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de TanStack/form
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 88/100
Mantenedores costumam responder em até 1 dia
-
Submit listener exceptions leave isSubmitting stuck trueTalvez já em andamento @henricop assumiu há 14 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 1 dia
-
handleSubmit calls onSubmit again while a submit is still pending (since 1.33.1)Talvez já em andamento @twotnguyen assumiu há 14 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Mantenedores costumam responder em até 1 dia
-
`isDefaultValue` is wrong when a field-level `defaultValue` is `null`Talvez já em andamento @fenet-as assumiu há 40 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
TanStack/form#2427 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Async validator doesn't re-trigger `isValidating` after first failed validationTalvez já em andamento @drewsephski assumiu há 44 dias. Aberta
Dificuldade 2/5 1-2 dias Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 1 dia
Todas as issues de TanStack/form
Issues semelhantes
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 92/100
lingdojo/kana-dojo#34449 · 1 comentário · 5 reações ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
drizzle-team/drizzle-orm#6726 ·
Mantenedores costumam responder em até 2 dias
-
bug platform-desktop platform-windows
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
Termix-SSH/Termix#1951 · 2 comentários ·
Mantenedores costumam responder em até 1 dia
-
Grok provider voice list shows 5 of xAI's 28 built-in voicesTalvez já em andamento @hkjarral assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 80/100
hkjarral/AVA-AI-Voice-Agent-for-Asterisk#883 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100