TanStack / TanStack/form

Using next.js server actions, fields are set to undefined

Open
#2,089 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

v1 v2: needs investigation
Dominant language
TypeScript
Stars
6.7k
Forks
682
Avg merge
5d 18h
Merged PRs (30d)
7

Description

Describe the bug

When going from one route to another one that has a tanstack form, all fields are set to default value initially and then undefined right after. This causes an error on UI.

Assume 2 routes / and /form and the /form route has the tanstack form. The problem only happens (as far as I can tell) when:

  • User goes to / route.
  • User clicks a link on the page that redirects them to /form route
  • All fields on the form are set to their default values first then to undefined

If you refresh the page in the above example, or you directly go to /form route by entering the URL on your address bar and pressing enter, the problem doesn't occur. It appears that this only happens while routing the user from one page in the app to the /form page.

Your minimal, reproducible example

https://codesandbox.io/p/devbox/pf2wkh

Steps to reproduce
  1. Go to "/" route and open the console
  2. Click "Go to Form" link to go to "/form"
  3. Notice on the console prints:
email value default@gmail.com
password value 123456789
email value undefined
password value undefined

If you are running on strict mode you'll see logs twice due to double render

  1. If you refresh the page you'll notice that they are not set to undefined
Expected behavior

Fields shouldn't be set to undefined

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform
  • OS: MacOS
  • Browser: Edge
  • 143.0.3650.96 (arm64)
TanStack Form adapter

react-form

TanStack Form version

1.28.5

TypeScript version

^5

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked CodeSandbox reproduction and the React form on the /form route, then reproduce client navigation from / to /form with the listed TypeScript and TanStack Form versions. Compare the form state during initial render and after navigation. Done means the fields retain their default values and the navigation path no longer produces undefined values.

Written by the indexing model from the issue text.

Assessment

Tech stack
next.js, react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.