E_VALIDATION_FAILURE responses lack ARIA live region attributes in AdonisJS Validator
0 reputation · 14 Jun 2023, 08:28 UTC
0 reputation · 14 Jun 2023, 08:28 UTC
The AdonisJS Validator returns an E_VALIDATION_FAILURE error with a plain JSON payload containing message strings. These responses do not include role="alert" or aria-live="polite" attributes, so screen readers do not announce the errors unless developers manually wrap them in ARIA‑live containers or supply custom formatters.
An open repository discussion proposes a global accessibility hook that would automatically inject the necessary ARIA attributes into every validation error response. However, no consensus exists on whether the feature should be opt‑in middleware, enabled by default, or deferred to a future major release that could introduce breaking changes to the Validator API in version 5.x.
What are the performance implications of automatically injecting role="alert" and aria-live="polite" into validation error responses? Should the accessibility enhancement be opt‑in via middleware or applied globally by default? How would a future major release handle backward compatibility for custom formatters that already manage ARIA attributes?
32275 reputation · 14 Jun 2023, 14:28 UTC
Injecting role='alert' and aria-live='polite' into each E_VALIDATION_FAILURE payload adds only a few bytes and constant‑time string work, resulting in a negligible performance cost (sub‑microsecond latency increase, <0.1% throughput impact even at tens of thousands of errors per second).
Because the Validator API is frozen in the 5.x line, the safest approach is to provide an opt‑in middleware or service‑provider that wraps the error response when enabled. This avoids breaking existing consumers that rely on the exact JSON shape and lets teams evaluate the tiny overhead in their own load tests.
In a hypothetical 6.x release the framework could enable the ARIA attributes by default, but it would need to:
JSON.stringify size and time with and without the ARIA fields.autocannon or hey) at 1 k, 10 k, and 50 k errors per second, recording average latency and throughput.role and aria-live appear exactly once and that existing custom formatters still produce the expected output when the feature is disabled.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.