Skip to content

form.reset(value) is not resetting defaultValues to a provided value #1490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ilialksv opened this issue May 7, 2025 · 7 comments
Open
Labels

Comments

@ilialksv
Copy link

ilialksv commented May 7, 2025

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

  1. Go to the Stackblitz url.
  2. Change values in input(s).
  3. Click "Submit" button.
  4. After submit, defaultValues are being reset to the new ones (you can see it in console).
  5. By the next render, defaultValues are 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

no-reset.mp4

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

@xargr
Copy link

xargr commented May 8, 2025

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

@harry-whorlow
Copy link
Contributor

harry-whorlow commented May 8, 2025

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()

@ilialksv
Copy link
Author

ilialksv commented May 8, 2025

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.

@harry-whorlow
Copy link
Contributor

harry-whorlow commented May 8, 2025

@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

@ilialksv
Copy link
Author

ilialksv commented May 8, 2025

@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!

@harry-whorlow
Copy link
Contributor

I have a fix ready over at 1494, I just need a CR and it should be deployed... sorry for the delay 😄

@ilialksv
Copy link
Author

That’s great news! Thanks for getting this sorted out so quickly. Really looking forward to the release)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants