-
Notifications
You must be signed in to change notification settings - Fork 402
fix(clerk-js): Ensure errors are being read to screen readers #7111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(clerk-js): Ensure errors are being read to screen readers #7111
Conversation
🦋 Changeset detectedLatest commit: b3415aa The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughAdds a visually hidden ARIA live region to FormControl to announce feedback updates to screen readers, removes per-feedback aria-live attributes, updates imports, and tightens many tests to assert feedback via element-specific selectors and the live region's content/positioning. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant FormControl
participant LiveRegion as "Visually Hidden\nLive Region"
participant ScreenReader
User->>FormControl: change input / submit
FormControl->>FormControl: compute feedback (error/success)
FormControl->>LiveRegion: update hidden text (polite)
LiveRegion->>ScreenReader: ARIA live announcement
ScreenReader->>User: announces feedback
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (6)
🧰 Additional context used📓 Path-based instructions (16)**/*.{js,jsx,ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
**/*.{ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
integration/**📄 CodeRabbit inference engine (.cursor/rules/global.mdc)
Files:
integration/**/*📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Files:
integration/**/*.{test,spec}.{js,ts}📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Files:
**/*.{js,ts,tsx,jsx}📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Files:
packages/clerk-js/src/ui/**/*.{ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/clerk-js-ui.mdc)
Files:
packages/**/*.{ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
packages/**/*.{ts,tsx,d.ts}📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
**/*.{jsx,tsx}📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
packages/**/*.{test,spec}.{js,jsx,ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Files:
packages/{clerk-js,elements,themes}/**/*.{test,spec}.{js,jsx,ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Files:
**/*.tsx📄 CodeRabbit inference engine (.cursor/rules/react.mdc)
Files:
**/*.test.{jsx,tsx}📄 CodeRabbit inference engine (.cursor/rules/react.mdc)
Files:
**/__tests__/**/*.{ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)
Files:
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
🔇 Additional comments (8)
Comment |
|
!snapshot |
|
Hey @alexcarpenter - the snapshot version command generated the following package versions:
Tip: Use the snippet copy button below to quickly install the required packages. npm i @clerk/agent-toolkit@0.1.45-snapshot.v20251031161044 --save-exact
npm i @clerk/astro@2.14.3-snapshot.v20251031161044 --save-exact
npm i @clerk/backend@2.19.2-snapshot.v20251031161044 --save-exact
npm i @clerk/chrome-extension@2.7.11-snapshot.v20251031161044 --save-exact
npm i @clerk/clerk-js@5.103.2-snapshot.v20251031161044 --save-exact
npm i @clerk/elements@0.23.76-snapshot.v20251031161044 --save-exact
npm i @clerk/clerk-expo@2.17.4-snapshot.v20251031161044 --save-exact
npm i @clerk/expo-passkeys@0.4.13-snapshot.v20251031161044 --save-exact
npm i @clerk/express@1.7.44-snapshot.v20251031161044 --save-exact
npm i @clerk/fastify@2.5.1-snapshot.v20251031161044 --save-exact
npm i @clerk/localizations@3.26.5-snapshot.v20251031161044 --save-exact
npm i @clerk/nextjs@6.34.2-snapshot.v20251031161044 --save-exact
npm i @clerk/nuxt@1.11.3-snapshot.v20251031161044 --save-exact
npm i @clerk/clerk-react@5.53.5-snapshot.v20251031161044 --save-exact
npm i @clerk/react-router@2.1.7-snapshot.v20251031161044 --save-exact
npm i @clerk/remix@4.13.10-snapshot.v20251031161044 --save-exact
npm i @clerk/shared@3.30.0-snapshot.v20251031161044 --save-exact
npm i @clerk/tanstack-react-start@0.26.6-snapshot.v20251031161044 --save-exact
npm i @clerk/testing@1.13.10-snapshot.v20251031161044 --save-exact
npm i @clerk/themes@2.4.31-snapshot.v20251031161044 --save-exact
npm i @clerk/types@4.97.0-snapshot.v20251031161044 --save-exact
npm i @clerk/vue@1.14.10-snapshot.v20251031161044 --save-exact |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks for fixing this!
| // Verify there's a screen-reader-only aria-live region with the error content | ||
| const ariaLiveRegions = container.querySelectorAll('[aria-live="polite"]'); | ||
| expect(ariaLiveRegions.length).toBeGreaterThanOrEqual(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: If I understood the bug correctly, the announcement did not work because aria-live only announces changes to the DOM element, so maybe this test should also assert that this element is already in the DOM without errors before the set error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
packages/clerk-js/src/ui/elements/__tests__/PlainInput.test.tsx (2)
235-248: Pre-state validation addresses past feedback, but consider stricter assertions.The pre-state validation correctly addresses the previous review comment about verifying the aria-live region exists before content changes. This ensures the region can announce updates properly.
However, line 237 uses
toBeGreaterThanOrEqual(1), which is lenient. If the implementation accidentally creates multiple aria-live regions, this test would still pass. Consider whether you should assert an exact count to catch regressions.- expect(preRegions.length).toBeGreaterThanOrEqual(1); + expect(preRegions.length).toBe(1);
254-282: Consider strengthening assertions for completeness.The test correctly validates the screen-reader-only live region updates, but could be more comprehensive:
Reuse pre-state region: Lines 259-262 re-query for the screen-reader-only region. Consider reusing
preSrOnlyfrom the pre-state validation (lines 238-242) to ensure you're testing the same element throughout.Verify aria-describedby transitions: The test validates the live region content but doesn't check that the input's
aria-describedbyattribute correctly transitions fromerror-firstnametofirstname-success-feedback. This is covered in other tests, but including it here would make this test more self-contained.Same leniency issue: Line 256 uses
toBeGreaterThanOrEqual(1)which could mask duplicate regions.- const ariaLiveRegions = container.querySelectorAll('[aria-live="polite"]'); - expect(ariaLiveRegions.length).toBeGreaterThanOrEqual(1); - - // Find the screen reader only region (it will have the visually hidden styles) - const srOnlyRegion = Array.from(ariaLiveRegions).find(el => { - const style = window.getComputedStyle(el); - return style.position === 'absolute' && style.width === '1px'; - }); - expect(srOnlyRegion).toBeDefined(); + // Reuse the pre-state region to ensure consistency + expect(preSrOnly).toBeDefined(); + const srOnlyRegion = preSrOnly!; expect(srOnlyRegion).toHaveTextContent(/Some Error/i); + + // Verify input aria-describedby references the error + expect(inputEl).toHaveAttribute('aria-describedby', 'error-firstname'); + expect(inputEl).toHaveAttribute('aria-invalid', 'true');And after the success transition:
// Verify the screen reader only region updated its content expect(srOnlyRegion).toHaveTextContent(/Some Success/i); + + // Verify input aria-describedby references the success feedback + expect(inputEl).toHaveAttribute('aria-describedby', 'firstname-success-feedback'); + expect(inputEl).toHaveAttribute('aria-invalid', 'false');
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
packages/clerk-js/src/ui/elements/__tests__/PlainInput.test.tsx(6 hunks)
🧰 Additional context used
📓 Path-based instructions (13)
packages/clerk-js/src/ui/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/clerk-js-ui.mdc)
packages/clerk-js/src/ui/**/*.{ts,tsx}: Element descriptors should always be camelCase
Use element descriptors in UI components to enable consistent theming and styling via appearance.elements
Element descriptors should generate unique, stable CSS classes for theming
Element descriptors should handle state classes (e.g., cl-loading, cl-active, cl-error, cl-open) automatically based on component state
Do not render hard-coded values; all user-facing strings must be localized using provided localization methods
Use the useLocalizations hook and localizationKeys utility for all text and error messages
Use the styled system (sx prop, theme tokens, responsive values) for custom component styling
Use useCardState for card-level state, useFormState for form-level state, and useLoadingStatus for loading states
Always use handleError utility for API errors and use translateError for localized error messages
Use useFormControl for form field state, implement proper validation, and handle loading and error states in forms
Use localization keys for all form labels and placeholders
Use element descriptors for consistent styling and follow the theme token system
Use the Card and FormContainer patterns for consistent UI structure
Files:
packages/clerk-js/src/ui/elements/__tests__/PlainInput.test.tsx
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
packages/clerk-js/src/ui/elements/__tests__/PlainInput.test.tsx
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/clerk-js/src/ui/elements/__tests__/PlainInput.test.tsx
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/clerk-js/src/ui/elements/__tests__/PlainInput.test.tsx
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/clerk-js/src/ui/elements/__tests__/PlainInput.test.tsx
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Preferreadonlyfor properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertionsfor literal types:as const
Usesatisfiesoperator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noanytypes without justification
Proper error handling with typed errors
Consistent use ofreadonlyfor immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
packages/clerk-js/src/ui/elements/__tests__/PlainInput.test.tsx
**/*.{jsx,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{jsx,tsx}: Use error boundaries in React components
Minimize re-renders in React components
**/*.{jsx,tsx}: Always use functional components with hooks instead of class components
Follow PascalCase naming for components:UserProfile,NavigationMenu
Keep components focused on a single responsibility - split large components
Limit component size to 150-200 lines; extract logic into custom hooks
Use composition over inheritance - prefer smaller, composable components
Export components as named exports for better tree-shaking
One component per file with matching filename and component name
Use useState for simple state management
Use useReducer for complex state logic
Implement proper state initialization
Use proper state updates with callbacks
Implement proper state cleanup
Use Context API for theme/authentication
Implement proper state selectors
Use proper state normalization
Implement proper state persistence
Use React.memo for expensive components
Implement proper useCallback for handlers
Use proper useMemo for expensive computations
Implement proper virtualization for lists
Use proper code splitting with React.lazy
Implement proper cleanup in useEffect
Use proper refs for DOM access
Implement proper event listener cleanup
Use proper abort controllers for fetch
Implement proper subscription cleanup
Use proper HTML elements
Implement proper ARIA attributes
Use proper heading hierarchy
Implement proper form labels
Use proper button types
Implement proper focus management
Use proper keyboard shortcuts
Implement proper tab order
Use proper skip links
Implement proper focus traps
Implement proper error boundaries
Use proper error logging
Implement proper error recovery
Use proper error messages
Implement proper error fallbacks
Use proper form validation
Implement proper error states
Use proper error messages
Implement proper form submission
Use proper form reset
Use proper component naming
Implement proper file naming
Use proper prop naming
Implement proper...
Files:
packages/clerk-js/src/ui/elements/__tests__/PlainInput.test.tsx
packages/**/*.{test,spec}.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Unit tests should use Jest or Vitest as the test runner.
Files:
packages/clerk-js/src/ui/elements/__tests__/PlainInput.test.tsx
packages/{clerk-js,elements,themes}/**/*.{test,spec}.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Visual regression testing should be performed for UI components.
Files:
packages/clerk-js/src/ui/elements/__tests__/PlainInput.test.tsx
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.
Files:
packages/clerk-js/src/ui/elements/__tests__/PlainInput.test.tsx
**/*.tsx
📄 CodeRabbit inference engine (.cursor/rules/react.mdc)
**/*.tsx: Use proper type definitions for props and state
Leverage TypeScript's type inference where possible
Use proper event types for handlers
Implement proper generic types for reusable components
Use proper type guards for conditional rendering
Files:
packages/clerk-js/src/ui/elements/__tests__/PlainInput.test.tsx
**/*.test.{jsx,tsx}
📄 CodeRabbit inference engine (.cursor/rules/react.mdc)
**/*.test.{jsx,tsx}: Use React Testing Library
Test component behavior, not implementation
Use proper test queries
Implement proper test isolation
Use proper test coverage
Test component interactions
Use proper test data
Implement proper test setup
Use proper test cleanup
Implement proper test assertions
Use proper test structure
Files:
packages/clerk-js/src/ui/elements/__tests__/PlainInput.test.tsx
**/__tests__/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)
**/__tests__/**/*.{ts,tsx}: Create type-safe test builders/factories
Use branded types for test isolation
Implement proper mock types that match interfaces
Files:
packages/clerk-js/src/ui/elements/__tests__/PlainInput.test.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (2)
packages/clerk-js/src/ui/elements/__tests__/PlainInput.test.tsx (2)
142-142: LGTM! Precise ID-based selectors improve test reliability.The updated selectors now target specific IDs (
#error-firstname,#firstname-info-feedback,#firstname-success-feedback) which align with the accessibility improvements in the PR. These precise selectors reduce brittleness and ensure tests verify the correct ARIA-described elements.Also applies to: 166-166, 181-181, 205-205, 213-213, 252-252, 268-268
225-225: LGTM! More descriptive test name.The renamed test case better describes the accessibility implementation: a visually hidden live region that announces feedback changes to screen readers in real time.
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/elements
@clerk/clerk-expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/clerk-react
@clerk/react-router
@clerk/remix
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/themes
@clerk/types
@clerk/upgrade
@clerk/vue
commit: |
|
Found 84 test failures on Blacksmith runners:
|
…g-announced-by-screen-readers
…g-announced-by-screen-readers
…g-announced-by-screen-readers
Description
Why Both Are Needed
So you get:
fixes USER-3837
Testing
Screen.Recording.2025-10-31.at.1.45.07.PM.mov
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
Summary by CodeRabbit
Bug Fixes
Tests
Chores