You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Reset form does not work as expected in combination with useStore #1798
{ keepDefaultValues: true }. this will set the data as new Default Value
I think you meant, this will keep the existing default values.
Regardless, yes, that fixed the problem. I'm not quite sure why modifying the default values or not should influence the end result. It seems to me even if I do replace the default values with the new values, the end state should reflect the values I passed into reset, i.e. x === '5'.
after the reset occurred, a new render cycle with an update value starts.
the form options are reevaluated, and it notices that the incoming defaultValues are not the same as the currently saved defaultValues.
this would usually be ignored because the form is touched, but the reset form now accepts defaultValues again. This is intended to be for async initial values, but it undoes your form.reset-provided values
@LeCarbonator ok so... it's a bug? sounds like a bug.
This is a problem because setting values from an existing record in the db is a common pattern in my app. Because .reset has unexpected behaviors, I'm using this as a workaround but its not ideal because I have an unneeded copy of the form in state:
I think there is no need to manually reset the form values with useEffect, we can directly set the default values,
This is true, although syntactically defaultValues: serverData ?? { x: '1', date: new Date() }, makes more sense to me. Regardless, for this simple example, you are correct.
However, lets go to a more practical example, where you have multiple different queries and a need to transform those queries into your form data:
But then what about your custom loading state? You could depend on the loading state of the individual queries, but what if transformData takes a non-trivial amount of time to transform the data? (Yes, at some point, it makes sense to consider shifting this logic to the server but that's a whole separate rabbit hole that's out of scope for this discussion).
I think there is no need to manually reset the form values with useEffect, we can directly set the default values,
This is true, although syntactically defaultValues: serverData ?? { x: '1', date: new Date() }, makes more sense to me. Regardless, for this simple example, you are correct.
However, lets go to a more practical example, where you have multiple different queries and a need to transform those queries into your form data:
const form = useForm({ defaultValues: initialStaticValues });
useEffect(() => {
if (query1.data && query2.data) {
form.reset(transformData(query1.data, query2.data));
setValuesLoaded(true);
}
}, [query1.data, query2.data]);
However, I've found this type of logic does not work reliably in tanstack.
Yes, you could shift the transform logic to inside the useForm:
const form = useForm({ defaultValues: query1.data && query2.data ? transformData(query1.data, query2.data) : initialStaticValues });
But then what about your custom loading state? You could depend on the loading state of the individual queries, but what if transformData takes a non-trivial amount of time to transform the data? (Yes, at some point, it makes sense to consider shifting this logic to the server but that's a whole separate rabbit hole that's out of scope for this discussion).
In a nutshell, to me, it seems like
const form = useForm({ defaultValues: initialStaticValues });
form.reset(newValues);
does not work reliably in all situations and that is causing bugs for me (and presumably others).
form.reset(newValues) was working fine until I refactored using form composition. I didn't change anything about the form's logic other than extracting it into reusable form and field components
But I did find a workaround that so far seems to fix it for me. I save my defaultValues in a state, and pass that to useFormState, and then in onSubmit I call setDefaultValues followed by reset.
Hi maintainers! We investigated #1798 and the related reset/re-render behavior in #1681. We noticed the existing proposals in #2218 and #2235 and wanted to coordinate before opening another PR.
Our local patch tracks the last defaultValues supplied through options (_lastOptionsDefaultValues) so values set by form.reset(newValues) survive repeated renders that pass unchanged stale options, while genuinely new async/prop-driven defaults can still be accepted. It also continues normal defaultState reconciliation rather than returning early from update().
We have regression coverage for the useStore reproduction, multiple subsequent renders, parameterless reset(), and genuinely new defaults; the form-core and react-form test suites and targeted checks pass locally.
Would you prefer that we open a separate PR for maintainer review, or would it be better to coordinate/consolidate with #2218 or #2235? We're happy to follow your preferred route.
Activity
Vijayabaskar56 commentedon Oct 10, 2025
Can You try
form.reset(data, { keepDefaultValues: true }){ keepDefaultValues: true }. this will set the data as new Default Value
marc-niclas commentedon Oct 11, 2025
I think you meant, this will keep the existing default values.
Regardless, yes, that fixed the problem. I'm not quite sure why modifying the default values or not should influence the end result. It seems to me even if I do replace the default values with the new values, the end state should reflect the values I passed into
reset, i.e.x === '5'.Vijayabaskar56 commentedon Oct 12, 2025
Yeah, Not Sure about that behavior, @LeCarbonator might give us some info on this ?
LeCarbonator commentedon Oct 12, 2025
I believe the main problem is this:
form.reset(values)resets to a new set of valuesform.reset-provided valuesmarc-niclas commentedon Oct 13, 2025
@LeCarbonator ok so... it's a bug? sounds like a bug.
This is a problem because setting values from an existing record in the db is a common pattern in my app. Because
.resethas unexpected behaviors, I'm using this as a workaround but its not ideal because I have an unneeded copy of the form in state:LeCarbonator commentedon Oct 13, 2025
Yeah, it's a bug, but it's one that is really difficult to work around. It needs some time to be properly looked at
mamlzy commentedon Oct 30, 2025
This bug is a blocker for me to use this library. I hope the contributors fix it as soon as possible. 🙏
smaindarkar commentedon Dec 30, 2025
I think there is no need to manually reset the form values with useEffect, we can directly set the default values,
@marc-at-brightnight @LeCarbonator @mamlzy
marc-niclas commentedon Dec 30, 2025
This is true, although syntactically
defaultValues: serverData ?? { x: '1', date: new Date() },makes more sense to me. Regardless, for this simple example, you are correct.However, lets go to a more practical example, where you have multiple different queries and a need to transform those queries into your form data:
However, I've found this type of logic does not work reliably in tanstack.
Yes, you could shift the transform logic to inside the
useForm:But then what about your custom loading state? You could depend on the loading state of the individual queries, but what if
transformDatatakes a non-trivial amount of time to transform the data? (Yes, at some point, it makes sense to consider shifting this logic to the server but that's a whole separate rabbit hole that's out of scope for this discussion).In a nutshell, to me, it seems like
does not work reliably in all situations and that is causing bugs for me (and presumably others).
smaindarkar commentedon Dec 31, 2025
Also, form.reset is not working only when we are observing any form property with useStore hook. And async initial values option is as per Tanstack Form documentation, https://tanstack.com/form/latest/docs/framework/react/guides/async-initial-values
@marc-at-brightnight
Vito-Ethan commentedon Feb 10, 2026
Facing the same issue. Reading through #1681 there's this comment about setting a timeout with the reset which works for me. #1681 (comment)
form.reset(newValues)was working fine until I refactored using form composition. I didn't change anything about the form's logic other than extracting it into reusable form and field componentsjens-kuerten commentedon Feb 22, 2026
I ran into the same problem.
Passing the option
{ keepDefaultValues: true }fixes the issue for some weird reason.ikea-niklas commentedon Mar 18, 2026
I just ran into the exact same problem.
@jens-kuerten workaround only fixes whats visible. If one adds another form.reset() below that line it resets it all back to what it was before. IE
But I did find a workaround that so far seems to fix it for me. I save my defaultValues in a state, and pass that to useFormState, and then in onSubmit I call setDefaultValues followed by reset.
Satjeet2005 commentedon Oct 16, 2026
Hi maintainers! We investigated #1798 and the related reset/re-render behavior in #1681. We noticed the existing proposals in #2218 and #2235 and wanted to coordinate before opening another PR.
Our local patch tracks the last
defaultValuessupplied through options (_lastOptionsDefaultValues) so values set byform.reset(newValues)survive repeated renders that pass unchanged stale options, while genuinely new async/prop-driven defaults can still be accepted. It also continues normaldefaultStatereconciliation rather than returning early fromupdate().We have regression coverage for the
useStorereproduction, multiple subsequent renders, parameterlessreset(), and genuinely new defaults; theform-coreandreact-formtest suites and targeted checks pass locally.Would you prefer that we open a separate PR for maintainer review, or would it be better to coordinate/consolidate with #2218 or #2235? We're happy to follow your preferred route.