Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@sanrai
Copy link
Collaborator

@sanrai sanrai commented Jul 28, 2025

Add react-axe for run-time accessibility auditing

Description

This change integrates react-axe into our React app so that during local development, every rendered component is automatically audited for common accessibility (a11y) issues. Instead of running separate CLI checks or waiting for a manual audit, violations (e.g., missing alt text, insufficient color contrast, or improper ARIA attributes) will be logged directly to the browser console the moment components mount or update.

What's been added

A conditional block in our entry-point (usually index.js or App.jsx) that only runs when:

  • process.env.NODE_ENV !== 'production'
  • typeof window !== 'undefined' (i.e., client-side)

Inside that block:

/* eslint-disable-next-line global-require */
const ReactAxe = require('react-axe');
ReactAxe(React, ReactDOM, 1000);
  • We throttle audits to at most one check per second (1000ms)
  • Any a11y violations detected by axe-core will appear in the browser console, with pointers to the exact DOM node or component source line

Why this matters

Immediate feedback: Instead of discovering accessibility bugs during a late-stage QA pass or CI job, developers see them instantly while coding.

Stronger developer habits: By surfacing missing aria-* attributes, unlabeled form controls, and other WCAG-related issues as warnings, engineers learn to build with semantic, accessible markup from day one.

Zero impact on production: We only bundle react-axe in non-production builds. Once NODE_ENV === 'production', the entire block is excluded, so end users don't incur any runtime overhead.

How to verify

  1. With your React dev server running (npm run start or equivalent), open the browser console

  2. Navigate through the app and intentionally introduce an a11y issue (e.g., remove an <img alt="…"> or render a <button> without a label)

  3. Observe that violations appear in the console immediately, including:

    • A description of the rule
    • A link to the WCAG guideline
    • A snippet of the problematic DOM

Future Notes

If we upgrade to React 18+ and switch to the new createRoot API, we may consider adopting @axe-core/react instead, since it provides explicit support for concurrent rendering. For now, [email protected] works as expected in our dev environment.

Demo

image

@github-actions
Copy link

Core Web Vitals Metrics

Metric Value
LCP N/A s
FID N/A ms
CLS N/A

Recorded at: 2025-07-28T18:41:46.779Z
PR: #302

@sanrai sanrai changed the title build(mwpw-177058): Adds monitoring for a11y build(mwpw-177058): adds monitoring for a11y Jul 28, 2025
@sanrai sanrai changed the title build(mwpw-177058): adds monitoring for a11y build(mwpw-177058): adds monitoring for a11y & 40% perf improvement Jul 28, 2025
@github-actions
Copy link

Core Web Vitals Metrics

Metric Value
LCP N/A s
FID N/A ms
CLS N/A

Recorded at: 2025-07-28T18:46:39.477Z
PR: #302

@github-actions
Copy link

Core Web Vitals Metrics

Metric Value
LCP N/A s
FID N/A ms
CLS N/A

Recorded at: 2025-07-28T18:49:07.426Z
PR: #302

@sanrai sanrai changed the title build(mwpw-177058): adds monitoring for a11y & 40% perf improvement build(mwpw-177058): adds monitoring for a11y & 40% build reduction Jul 28, 2025
@github-actions
Copy link

Core Web Vitals Metrics

Metric Value
LCP N/A s
FID N/A ms
CLS N/A

Recorded at: 2025-07-28T19:13:37.624Z
PR: #302

@sanrai sanrai merged commit b83d003 into main Jul 28, 2025
45 of 46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant