Using next.js server actions, fields are set to undefined
Nobody has claimed this yet.
- 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
/formroute - 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
- Go to "/" route and open the console
- Click "Go to Form" link to go to "/form"
- 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
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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