Async validation race condition with validateOnMount in vee-validate v4
0 reputation · 29 Oct 2020, 00:03 UTC
Race conditions during rapid prop changes
When using validateOnMount with asynchronous validation rules in vee-validate v4, rapid prop or schema changes can trigger overlapping validation requests. The library does not provide a built-in cancellation mechanism, so a slower earlier request may resolve after a faster later one, overwriting the current error state with stale results.
Constraints and uncertainty
- The
useFieldcomposable registers fields in a globalFormContextmap keyed by name; dynamic name changes without a key change leave duplicate registrations. - No documented API exists to abort in-flight async validators or to correlate responses with the validation cycle that initiated them.
- Debouncing at the rule level mitigates frequency but does not guarantee ordering when network latency varies.
Goal: determine a reliable pattern to ensure only the most recent validation cycle updates the field's error state without relying on external abort controllers for every rule.
- Does vee-validate v4 expose any internal validation cycle identifier that can be checked inside an async rule before setting errors?
- Can the
validateOnMountbehavior be scoped to a specific schema version so that stale cycles are ignored automatically? - Which composition of
useFieldoptions (validateOnMount,keepValuesOnUnmount, manualvalidatecalls) yields deterministic async validation ordering?