TanStack / TanStack/form

form.reset during onSubmit ignores new default values

Open
#1,681 4 comments 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area: runtime scope: react type: bug v1
Dominant language
TypeScript
Stars
6.7k
Forks
682
Avg merge
5d 18h
Merged PRs (30d)
7

Description

Describe the bug

The issue is that if you use the form's reset function from inside the form's onSubmit with new default values, they will be ignored.
This only happens if used in combination with form store-related watches such as "isDirty"
From the troubleshooting done by @LeCarbonator , it appears to be a race condition between handleSubmit and reset.

Your minimal, reproducible example

https://stackblitz.com/edit/vitejs-vite-jd2ttqqx?file=src%2FApp.tsx

Steps to reproduce
  1. Uncheck the checkbox.
  2. Click the Submit button
  3. See how the form goes back to the original default values instead of the new ones.
Expected behavior

Since we are calling the reset function with new values, those values should become the new form values.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform
  • OS: Any
  • Browser: Any
  • Node Version: 22
TanStack Form adapter

react-form

TanStack Form version

1.18.0

TypeScript version

v5.8.3

Additional context

A chat around this issue can be found here

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 StackBlitz reproduction and trace the interaction between handleSubmit, reset with new default values, and the isDirty form-store watch. Reproduce the issue by unchecking the checkbox and submitting, then verify that the supplied reset values remain the form's values instead of reverting to the original defaults.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.