Does it make sense to trigger onChangeAsync when onSubmit is called?
As
onChangeAsync
is mostly there for devs to make API calls which are debounceable, does it make sense to have it retriggered when onSubmit is called?
Should we add an option to disable this behaviour?15 Replies
genetic-orange•2y ago
onChangeAsync
should already be triggered by onSubmit, just like onChange
I don't think there should be a way to disable this functionality. Why would you want to?quickest-silverOP•2y ago
Because I am already querying my API for a « does user exist » on my username field.
As there is a debounce on this field there are two issues:
- a request is sent to my api but this field has already been validated
- the debounce on this field is also used on the submit
genetic-orange•2y ago
Right, but consider this:
- User inputs a value, no matching username
- Between debounced, user changes value to something matching
- Submits form without waiting for debounce
You just encountered a bug
quickest-silverOP•2y ago
Imo, when pressing submit, the api call should be instantly. There shouldn't be any debounce
User inputs a value, no matching username
Between debounced, user changes value to something matching
Submits form without waiting for debounce
Submits form without waiting for debounce as the api call will still validate the field but this time it will be done instantly
Wdyt?
genetic-orange•2y ago
That's how it works today 😄
The debounce applies so that the user doesn't DDOS your backend haha
But then on submit the debounce is ignored
quickest-silverOP•2y ago
well, it's not ignored on submit, that's my point 😅
genetic-orange•2y ago
If you're not experiencing this behavior for any reason please let us know - that would be considered a bug that we'd want a minimal reproduction for that we can test against and fix
quickest-silverOP•2y ago
maybe there is a regression, I dunno
genetic-orange•2y ago
Could be! Let's open a GH issue with a minimal repro and I'll look into it 🙂
quickest-silverOP•2y ago
sure, I will provide a repro 👍
genetic-orange•2y ago
I thought we had tests for exactly this 🤔
Yeah we definitely don't - that's a shame.
Oooooh I see the problem. I might be able to get this fixed today(ish) assuming ngConf doesn't pull 100% of my attention (I'm there now)
quickest-silverOP•2y ago
I checked on the project repo itself, it can be seen on the react example directly : )
genetic-orange•2y ago
Yup! I think I know enough now to fix it
genetic-orange•2y ago
Hey @Bamboozilla can you make an issue here?
https://github.com/TanStack/form/issues
Even if it's relatively light on the details, I just need a good reminder to work on it prior to 1.x
GitHub
Issues · TanStack/form
🤖 Powerful and type-safe form state management for the web. TS/JS, React Form, Solid Form, Lit Form and Vue Form. - Issues · TanStack/form
quickest-silverOP•2y ago
Done + PR 👍