Skip to content

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

@Raepheles

Description

@Raepheles

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions