form.reset(value) is not resetting defaultValues to a provided value
Describe the bug
It seems like form.reset(value) is updating defaultValues, but by the next render defaultValues are being reset to the initially provided ones. So, as a result, there is no difference whether to call form.reset(value) or just form.reset() because they lead to the same result.
Your minimal, reproducible example
https://stackblitz.com/edit/vitejs-vite-x8k3rfrs?file=src%2FApp.tsx
Steps to reproduce
- Go to the Stackblitz url.
- Change values in input(s).
- Click "Submit" button.
- After submit,
defaultValuesare being reset to the new ones (you can see it in console). - By the next render,
defaultValuesare back to the initial ones.
Expected behavior
As a user I expect that defaultValues are updated with the values provided to form.reset method and not being reset to the initial defaultValues.
How often does this bug happen?
Every time
Screenshots or Videos
https://github.com/user-attachments/assets/bf1f3a75-9436-44a1-9015-1d282185f425
Platform
- OS: Windows 11
- Browser: Chrome
- Version: 135.0.7049.116
TanStack Form adapter
react-form
TanStack Form version
v1.9.1
TypeScript version
v5.8.3
Additional context
No response
the question here is what's the ideal behaviour and if the default value meant to be always rendered when there isn't value or they have to be rendered only in the first rendering
It seems to only be when form.reset is called in an async...
https://stackblitz.com/edit/tanstack-form-9kpziquv?file=src%2Findex.tsx&preset=node
You'll see from the stackblitz that form.reset() dose work correctly, but only when its not called inside async functions (click the reset, or reset with val)... However if you click the submit, then you'll get this weird wiping behaviour when form.reset() is called onSubmit()
Thanks for the explanation! But it's a bit of a confusing behavior. I think it's quite a common use case of this method, when you need to reset a value after updating some data inside an asynchronous function.
It would be great if this method would work correctly in this case too, so that we wouldn't have to invent ways around it.
@ilialksv, no I think you've misunderstood me, I think it's a bug... only, I was stating where its happening. π
I've narrowed it down a little further, form core handles this correctly, the react adaptor is where this appears to be happening, well it might be happening in the other adapters I haven't checked.
Theres a few issues like this that have opened in the past couple days, let me dig around a bit.
[update] correct functionality also exists in:
- core
- angular
- vue
@harry-whorlow Got it! Thanks for clarifying and for looking into it further.
By the way, I just wanted to express my appreciation for this package. It has been a great help in my projects. Thank you and the team for your hard work!
I have a fix ready over at 1494, I just need a CR and it should be deployed... sorry for the delay π
Thatβs great news! Thanks for getting this sorted out so quickly. Really looking forward to the release)
#1494 has been merged. From what I can tell, the stackblitz reproduction works with v1.14.1 now.