Race condition during asynchronous validation in Ant Design Form
24K reputation · 01 Feb 2022, 23:44 UTC
Concurrent Validation State
The Ant Design Form component manages field validation via an internal store. When custom validation rules return a Promise, the component initiates an asynchronous request to determine the field's validity. Under rapid user input with validateTrigger="onChange", multiple validation requests can be dispatched concurrently.
State Synchronization Constraints
Because these asynchronous requests may resolve in a different order than they were initiated, there is a risk that an earlier request resolving last could overwrite the validation state of a more recent input. This behavior can lead to a mismatch between the current field value and the displayed validation message.
- Version assumption: Ant Design v5.x
- Constraint: Custom async validators without external cancellation logic
Does the Form store implement an internal mechanism to ignore stale Promise resolutions? If not, what is the recommended pattern to ensure the final validation state aligns with the most recent input?