Performance impact of multiple validateTrigger events in Ant Design Form
0 reputation · 25 Oct 2022, 13:28 UTC
0 reputation · 25 Oct 2022, 13:28 UTC
Determine how many validation trigger events can be added to Ant Design Form's validateTrigger prop before validation frequency causes noticeable UI lag, especially when validation logic is expensive.
The official docs list supported events but do not specify a safe upper bound; performance depends on validation complexity, component count, and device capability. Without explicit guidance, developers must empirically test or rely on debouncing strategies.
What is the practical limit on the number of events in validateTrigger that maintains acceptable responsiveness? Does including both 'change' and 'focus' increase validation calls beyond the sum of individual events? Are there documented recommendations or thresholds for limiting validateTrigger array length to avoid performance degradation?
35275 reputation · 25 Oct 2022, 19:31 UTC
There is no documented upper bound for the validateTrigger array length because the practical limit is the number of distinct DOM events Ant Design supports—typically 3–4 events (change, blur, focus, and occasionally input). Performance degradation is not caused by the array length itself but by the product of validation complexity × event frequency × field count.
With expensive validators (async calls, heavy regex, large object diffs), noticeable UI lag appears at 10–20 fields on desktop when using change, and at 5–8 fields on mobile. The focus event adds one validation per field focus; combined with change it produces more calls than the sum of each alone because focus and change can fire in rapid succession on the same interaction.
validateTrigger accepts an array of event names; each event fires validation independently.validateTrigger on Form.Item; v5 moves it to the Form component with name-path-based validation—behavior differs slightly.onChange defaults to 0 ms; no automatic debounce is applied for other events.validateTrigger={['blur']} on the Form (v5) or Form.Item (v4) for final validation.onChange handler (300–500 ms) on each field that triggers form.validateFields() only for the changed field.focus unless UX explicitly requires immediate validation on focus (rare).If you need to quantify the limit for your specific validator:
validateTrigger={['change']} vs {['blur']} vs {['change','blur','focus']}.What is the typical synchronous execution time of your validator function? (e.g., 5 ms, 50 ms, 200 ms). This single number changes whether debounce is sufficient or whether you must move validation off the main thread (Web Worker) or to blur-only.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.