-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
Describe the bug
Hi Refine team, thanks for the great library! I’ve noticed an issue with useForm. When using useForm from @refinedev/core with auto-save enabled, requests are triggered multiple times within the specified debounce window. This means the form state changes are not correctly grouped and debounced, instead, they are sent as individual delayed requests.
Looking at the source of the useForm hook, it appears that multiple instances of asyncDebounce are created. Each instance corresponds to a single form state update rather than grouping changes within the debounce window.
refine/packages/core/src/hooks/form/index.ts
Lines 305 to 309 in 8c403b2
| const onFinishAutoSave = asyncDebounce( | |
| (values: TVariables) => onFinish(values, { isAutosave: true }), | |
| props.autoSave?.debounce || 1000, | |
| "Cancelled by debounce", | |
| ); |
I'm using headless refine with the latest version of Mantine. As a workaround, I wrapped the onFinishAutoSave function returned by useFrom in a useDebouncedCallback hook.
Steps To Reproduce
import { useForm } from "@refinedev/core";
useForm({
autoSave: {
enabled: true,
debounce: 2000,
},
...
});Bind form-state changes to onFinishAutoSave(values) and modify any input field. Then observe how in the browser’s Network tab, multiple requests are triggered, even though the changes occur within the same time window of 2000ms.
Expected behavior
Only one request should be sent after the user stops editing or when the debounce interval elapses. No multiple requests for changes occurring within the same window.
Packages
@refinedev/core
Additional Context
No response