Commits on Source 3
-
François Martin authored
perf(frontend/forms): reduce calls to the backend if a value in an input field was already validated as unique When the focus is blurred on an input field, `react-hook-form` will perform unique validation against the backend. Additionally, to make sure a submitted form is always valid, it will perform validation again. This doesn't matter if the validation doesn't require a backend call, as those operations are very fast and don't result in any noticeable performance differences. However, in case of a unique validation, a call to the backend needs to be performed, which is very slow. This change will not make a call to the backend again, if the last validated value is the same as the current value. This reduces load on the backend and improves the performance on the frontend, as the call to the backend doesn't need to be performed again unnecessarily when submitting the form. Fixes #280
-
François Martin authored
Previously, the debounce mechanism delayed **every** single call to the validation by the specified amount of debouncing time. For example (with 1 second debouncing time): 1. In input field, type in: "a" 2. Waits 500ms 3. In input field, type in: "b" 4. Waits 250ms 5. In input field, type in: "c" 6. Waits 250ms 7. Calls `validate` function with `abc` (repeats from 1.) While this makes sense for typing in a text field, when clicking on the `submit` button, react-hook-form **also validates the form** and if it's successful, it submits the form. This means that even when clicking on the `submit` button, as **every** single call to the validation method is delayed by the debouncing time, it will also wait for the debouncing time before calling the validation method. This is not ideal, as the user needs to wait unnecessarily and since when clicking on the `submit` button, the user will not change anything anyways, debouncing is not necessary in those cases. This commit will change this behavior in a way that the **first** call to the validation method will be performed **instantly**, and every **following** call to the validation method will be delayed by the debouncing time. For example (again with 1 second debouncing time): For example (with 1 second debouncing time): 1. In input field, type in: "a" 2. Calls `validate` function with `a` 3. Waits 500ms 4. In input field, type in: "b" 5. Waits 250ms 6. In input field, type in: "c" 7. Waits 250ms 8. Calls `validate` function with `abc` (repeats from 1.) Since the first call to the method is performed instantly, this also means that when clicking on the `submit` button, the validation will be performed instantly. In most cases, when clicking on the submit button, it will not be necessary to make an API call to the backend, since it most likely was already validated after typing in the text field, which is why no delay would be expected in this case. Fixes #280
-
GitLab CI authored