Asynchronous field checks can tell a user whether a case reference is already used or whether an entered address is eligible. They are advisory while the person is typing. Requests can finish out of order, and an available value can become unavailable before the form is submitted. Give each field edit a generation or value identity, cancel old requests when practical, and apply a response only if it still matches the current input. Do not make the final submit depend solely on an earlier green indicator; the server must validate again while applying the write.
Asynchronous Field Validation Races
Working case
An operator enters reference 'CASE-47', then corrects it to 'CASE-62'. The CASE-62 check returns available first. A slow CASE-47 response arrives later and replaces the message with 'already used', even though the input now says CASE-62. Capture the value and a request sequence at dispatch. On response, compare both to current state before updating feedback. At submission, the server checks uniqueness and returns a field error if another operator claimed CASE-62 in the meantime. The UI must move focus to the right field without losing the typed value.
Implementation boundary
function isCurrentValidation(request, currentValue, currentSequence) {
return request.value === currentValue && request.sequence === currentSequence;
}
console.log(isCurrentValidation({ value: "CASE-47", sequence: 4 }, "CASE-62", 5));
// Output: falseThe identity check remains necessary even when AbortController cancels old fetches, because cancellation may race with a completed response or a non-abortable data source. Debounce only if it reduces wasted requests; show a checking state so silence is not mistaken for approval. Normalize values consistently between client and server, but let the server decide uniqueness in a transaction or database constraint. Associate feedback with the field, announce changes without repeating them on every keystroke, and distinguish network failure from invalid input.
Cost and boundaries
For e edits, an eager validator can send O(e) requests; debounce reduces typical traffic but adds feedback delay. Generation tracking takes O(1) state per field, while holding every old promise or controller can accumulate if cleanup is neglected. A uniqueness lookup cost depends on the server index, yet the client cannot infer its final truth from a past lookup. Prefer a modest delay and one active request for expensive checks, then measure request count and the time before actionable feedback on realistic typing speeds.
Failure trace
The first response overwrites the second because completion order differs from entry order. The page announces a false error and disables Send for review, trapping the operator. Guard response application by current value and sequence; allow a retry after a network failure. A separate race occurs after the form is submitted: the field looked free, but another operator saved it first. The server returns a conflict tied to the field, and the form must explain it without erasing unrelated entries or presenting the earlier green state as proof.
Verification
- Out-of-order responses never describe an old field value.
- Network failure is distinct from validation rejection.
- The server can reject a value that was previously shown as available.
Practice drill
Enter three references quickly, delay the first response until last, and inspect the field message after every completion. Abort one request just as it finishes and verify the generation check still protects the current value. Simulate a temporary network loss and ensure the message reads 'could not check' rather than 'invalid'. Submit a value that was available at check time but taken before write time; the server rejection must attach to the field and preserve the rest of the form.
Decision note
Treat async field feedback as a versioned hint and final server validation as the write boundary.
Common Mistakes
- Assuming abort alone prevents every stale callback.
- Disabling final submit forever after a validation network error.
- Treating an availability check as a reservation.
Connected lessons
Forms and Data Entry Workflows; Native Form Submission and Progressive Enhancement; Autosave, Draft Recovery, and Conflicts; Multipart Upload Progress and Retry Boundaries; React Effects and Request Races; Form submission: validate on the server and return field errors; Accessible forms: connect labels, errors, and focus.
Apply and check
Build Project: recoverable case intake form and review Web Development: rendering and forms decisions quiz.
