Skip to content

Conversation

alexcarpenter
Copy link
Member

@alexcarpenter alexcarpenter commented Oct 3, 2025

Description

  • Add aria-describedby to the password input that maps to the currently rendered feedback message
  • Ensures only the rendered feedback message contains aria-live='polite'

fixes USER-3619

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • New Features

    • Expanded feedback system to include success, warning, and info with standardized accessible IDs and consolidated feedback IDs used by inputs.
    • Animations and polite announcements are now tied to appearance settings and entry state.
  • Bug Fixes

    • Consistent aria-describedby and aria-invalid behavior when switching feedback types.
    • Centralized handling of live-region announcements so only entering feedback is politely announced.
  • Tests

    • Added tests covering feedback states, transitions, aria-describedby composition, and aria-live behavior.

Copy link

changeset-bot bot commented Oct 3, 2025

⚠️ No Changeset found

Latest commit: dde3fd5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Oct 3, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
clerk-js-sandbox Ready Ready Preview Comment Oct 7, 2025 7:28pm

Copy link
Contributor

coderabbitai bot commented Oct 3, 2025

Walkthrough

Centralizes feedback ID and aria-live handling: introduces feedbackMessageId, standardizes IDs (errors use error-${id}, others use ${id}-${type}-feedback), removes per-primitive aria-live attributes, and updates inputs, field hook/context, FormFeedback, tests, and related primitives to use the new pattern.

Changes

Cohort / File(s) Summary
Form field hook & context
packages/clerk-js/src/ui/primitives/hooks/useFormField.tsx
Replaces errorMessageId with feedbackMessageId; computes feedbackMessageId from debounced feedback (error-${id} for errors, ${id}-${type}-feedback otherwise); exposes it via provider, includes in memo deps, and updates sanitizeInputProps.
Input primitive
packages/clerk-js/src/ui/primitives/Input.tsx
Forwards feedbackMessageId; binds aria-describedby to feedbackMessageId when present; updates sanitization to remove errorMessageId and use feedbackMessageId.
Form control & feedback element
packages/clerk-js/src/ui/elements/FormControl.tsx
useFormTextAnimation now depends on appearanceAnimations and prefersReducedMotion; FormFeedback generates canonical IDs for all feedback types (error vs others) and forwards aria-live (polite when entering, off otherwise) to info components; minor comment/layout tweaks.
Field-level wiring
packages/clerk-js/src/ui/elements/FieldControl.tsx
Stops passing errorMessageId to FormFeedback; uses fieldId and debounced feedback only.
Text primitives (accessibility change)
packages/clerk-js/src/ui/primitives/FormErrorText.tsx, packages/clerk-js/src/ui/primitives/FormInfoText.tsx, packages/clerk-js/src/ui/primitives/FormSuccessText.tsx, packages/clerk-js/src/ui/primitives/FormWarningText.tsx
Removed per-primitive aria-live='polite' and removal of errorMessageId id assignment from these Text components; rendering and control flow otherwise unchanged.
Tests: PlainInput updates
packages/clerk-js/src/ui/elements/__tests__/PlainInput.test.tsx
Adds actions to set success/warning/info in mock wrapper; captures container for DOM assertions; updates queries/assertions to expect composed aria-describedby and new feedback IDs (e.g., #error-firstname, #firstname-success-feedback); adds tests for success feedback, error↔success transitions, and aria-live behavior.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as User
  participant IN as Input
  participant HF as useFormField (hook/context)
  participant FC as FormControl / FormFeedback
  participant TXT as InfoText Components

  U->>IN: type / interact
  IN->>HF: request field props (id, state, debounced feedback)
  HF-->>IN: { fieldId, feedbackType, feedbackMessageId, ... }

  alt compose aria-describedby
    IN->>IN: set aria-describedby = combine(existingIds, feedbackMessageId?)
  end

  IN->>FC: render feedback
  rect rgba(219,234,254,0.35)
    note right of FC #dbeafe: Centralized ID + live-region generation
    FC->>FC: generate id: if type==='error' -> "error-${id}" else -> "${id}-${type}-feedback"
    FC->>TXT: render text with generated id
    FC->>TXT: set aria-live = 'polite' when entering else 'off'
  end

  TXT-->>U: assistive tech receives updates
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

A rabbit scurries, changes in tow,
IDs reborn where live regions glow.
"error-" leads the cry, others softly sing,
A polite little whisper each time states spring.
Hops of code—accessibility's spring. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly and concisely summarizes the primary change of ensuring feedback messages are properly associated with their inputs, which aligns with the PR’s focus on mapping feedback via aria-describedby. It uses precise language without extraneous details or noise.
Linked Issues Check ✅ Passed The implementation adds aria-describedby to inputs using the new feedbackMessageId, updates FormFeedback to apply aria-live="polite" only to the currently rendered feedback element, and adjusts tests accordingly, fully satisfying USER-3619’s requirements for correct input association and live region updates.
Out of Scope Changes Check ✅ Passed All modifications, including renaming errorMessageId to feedbackMessageId, adjusting id generation patterns, and centralizing aria-live attributes in FormFeedback, directly support the goal of mapping feedback to inputs and controlling live regions, with no unrelated or extraneous changes introduced.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch alexcarpenter/user-3619-ensure-password-field-is-correctly-attached-to-the-aria-live

📜 Recent 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 651f11b and dde3fd5.

📒 Files selected for processing (1)
  • packages/clerk-js/src/ui/elements/__tests__/PlainInput.test.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • 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). (7)
  • GitHub Check: Integration Tests (nextjs, chrome, 15)
  • GitHub Check: Integration Tests (nextjs, chrome, 14)
  • GitHub Check: Integration Tests (machine, chrome)
  • GitHub Check: Integration Tests (sessions, chrome)
  • GitHub Check: Static analysis
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/clerk-js/src/ui/primitives/hooks/useFormField.tsx (1)

136-153: Minor: Type safety concern with sanitizeInputProps.

The destructuring correctly includes feedbackMessageId and the comment update is appropriate. However, the pattern of using @ts-ignore for dynamic property access (line 151) bypasses type checking.

Consider using a type-safe approach:

  keep?.forEach(key => {
-    /**
-     * Ignore error for the index type as we have defined it explicitly above
-     */
-    // @ts-ignore - Dynamic property access for form field props
-    inputProps[key] = obj[key];
+    if (key in obj) {
+      (inputProps as any)[key] = obj[key];
+    }
  });

This maintains type safety for the common case while explicitly handling dynamic access for the keep parameter.

📜 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 08bdebe and db1c3e0.

📒 Files selected for processing (8)
  • packages/clerk-js/src/ui/elements/FormControl.tsx (4 hunks)
  • packages/clerk-js/src/ui/elements/__tests__/PlainInput.test.tsx (4 hunks)
  • packages/clerk-js/src/ui/primitives/FormErrorText.tsx (0 hunks)
  • packages/clerk-js/src/ui/primitives/FormInfoText.tsx (0 hunks)
  • packages/clerk-js/src/ui/primitives/FormSuccessText.tsx (0 hunks)
  • packages/clerk-js/src/ui/primitives/FormWarningText.tsx (0 hunks)
  • packages/clerk-js/src/ui/primitives/Input.tsx (2 hunks)
  • packages/clerk-js/src/ui/primitives/hooks/useFormField.tsx (6 hunks)
💤 Files with no reviewable changes (4)
  • packages/clerk-js/src/ui/primitives/FormInfoText.tsx
  • packages/clerk-js/src/ui/primitives/FormSuccessText.tsx
  • packages/clerk-js/src/ui/primitives/FormWarningText.tsx
  • packages/clerk-js/src/ui/primitives/FormErrorText.tsx
🧰 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/primitives/hooks/useFormField.tsx
  • packages/clerk-js/src/ui/primitives/Input.tsx
  • packages/clerk-js/src/ui/elements/FormControl.tsx
  • 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/primitives/hooks/useFormField.tsx
  • packages/clerk-js/src/ui/primitives/Input.tsx
  • packages/clerk-js/src/ui/elements/FormControl.tsx
  • 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/primitives/hooks/useFormField.tsx
  • packages/clerk-js/src/ui/primitives/Input.tsx
  • packages/clerk-js/src/ui/elements/FormControl.tsx
  • 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/primitives/hooks/useFormField.tsx
  • packages/clerk-js/src/ui/primitives/Input.tsx
  • packages/clerk-js/src/ui/elements/FormControl.tsx
  • 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/primitives/hooks/useFormField.tsx
  • packages/clerk-js/src/ui/primitives/Input.tsx
  • packages/clerk-js/src/ui/elements/FormControl.tsx
  • 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
Avoid any type - prefer unknown when type is uncertain, then narrow with type guards
Use interface for object shapes that might be extended
Use type for unions, primitives, and computed types
Prefer readonly properties for immutable data structures
Use private for internal implementation details
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Prefer readonly for 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
Use const assertions for literal types: as const
Use satisfies operator 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 ...
No any types without justification
Proper error handling with typed errors
Consistent use of readonly for 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/primitives/hooks/useFormField.tsx
  • packages/clerk-js/src/ui/primitives/Input.tsx
  • packages/clerk-js/src/ui/elements/FormControl.tsx
  • 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/primitives/hooks/useFormField.tsx
  • packages/clerk-js/src/ui/primitives/Input.tsx
  • packages/clerk-js/src/ui/elements/FormControl.tsx
  • 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/primitives/hooks/useFormField.tsx
  • packages/clerk-js/src/ui/primitives/Input.tsx
  • packages/clerk-js/src/ui/elements/FormControl.tsx
  • 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/primitives/hooks/useFormField.tsx
  • packages/clerk-js/src/ui/primitives/Input.tsx
  • packages/clerk-js/src/ui/elements/FormControl.tsx
  • 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
**/*.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
🧬 Code graph analysis (1)
packages/clerk-js/src/ui/primitives/Input.tsx (1)
packages/clerk-js/src/ui/primitives/hooks/useFormField.tsx (1)
  • sanitizeInputProps (119-156)
⏰ 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: semgrep/ci
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (10)
packages/clerk-js/src/ui/elements/FormControl.tsx (3)

43-43: LGTM: Dependency array correctly updated.

The addition of appearanceAnimations to the dependency array is correct since it's used in the callback body (line 26).


146-149: LGTM: Clear ID generation strategy for all feedback types.

The unique ID generation for all feedback types (not just errors) enables proper aria-describedby associations. The distinction between error IDs (errorMessageId) and other feedback IDs (${id}-${type}-feedback) is well-documented and maintains backward compatibility.


184-184: Excellent: Centralized aria-live handling improves accessibility.

The conditional aria-live attributes ('polite' when shouldEnter is true, 'off' otherwise) ensure that only the currently visible feedback message is announced to screen readers. This prevents duplicate announcements during feedback transitions and properly coordinates with the aria-describedby associations established in the input components.

Also applies to: 196-196

packages/clerk-js/src/ui/primitives/hooks/useFormField.tsx (2)

14-14: LGTM: feedbackMessageId properly integrated into form field context.

The feedbackMessageId concept is correctly:

  • Added to the type definition
  • Computed based on debounced.feedback and debounced.feedbackType
  • Propagated through context value and memoization dependencies

This enables consistent ID generation across all feedback types for proper aria-describedby associations.

Also applies to: 53-56, 65-65, 82-82


53-56: No change needed for dual aria-describedby IDs
The dual ID strategy is intentional—Input.tsx joins both errorMessageId and feedbackMessageId for error cases (as verified by PlainInput.test.tsx), while FormControl/FormFeedback still render only errorMessageId for errors.

packages/clerk-js/src/ui/primitives/Input.tsx (1)

107-107: LGTM: aria-describedby properly composes multiple feedback IDs.

The implementation correctly:

  • Combines errorMessageId and feedbackMessageId when both are present
  • Filters out falsy values to avoid empty strings in the attribute
  • Joins IDs with a space as required by the ARIA specification
  • Falls back to undefined when no IDs are present, keeping the attribute clean

This ensures screen readers can access all relevant feedback messages associated with the input.

packages/clerk-js/src/ui/elements/__tests__/PlainInput.test.tsx (4)

24-26: Excellent: Comprehensive test setup and error feedback verification.

The test enhancements properly verify:

  • Addition of success/warning/info feedback controls alongside error
  • The container reference for DOM queries to verify element IDs
  • The updated error behavior including both error-firstname and firstname-error-feedback in aria-describedby
  • The presence and content of the error element with the correct ID

This confirms the dual ID strategy for errors is intentional and properly implemented.

Also applies to: 138-153


170-192: LGTM: Success feedback test validates new aria-describedby behavior.

The test correctly verifies:

  • Success feedback message rendering
  • aria-invalid set to 'false' for non-error feedback
  • aria-describedby contains only the success feedback ID (no dual ID for non-error cases)
  • The success element exists with the correct ID and content

This confirms the implementation properly distinguishes between error and non-error feedback types.


194-225: LGTM: Transition test confirms proper state management.

The test validates critical behavior when switching between feedback types:

  • Error → Success transition properly updates aria-describedby from dual IDs to single ID
  • aria-invalid correctly toggles from 'true' to 'false'
  • The success element replaces the error element in the DOM

This ensures the accessibility attributes remain consistent during feedback type changes.


227-258: Excellent: aria-live test confirms centralized live region management.

The test validates the key accessibility improvement introduced in this PR:

  • Error feedback has aria-live="polite" when visible
  • Success feedback has aria-live="polite" when visible
  • Only the currently visible feedback has aria-live="polite" (previous one switches to 'off')
  • At least one live region exists with 'polite' setting

This confirms the FormFeedback component properly manages live regions to prevent duplicate announcements while ensuring current feedback is announced to screen readers.

Comment on lines 66 to 68
// @ts-expect-error Typescript is complaining that `errorMessageId` and `feedbackMessageId` do not exist. We are clearly passing them from above.
const { errorMessageId, feedbackMessageId, ignorePasswordManager, feedbackType, ...fieldControlProps } =
sanitizeInputProps(fieldControl, ['errorMessageId', 'feedbackMessageId', 'ignorePasswordManager', 'feedbackType']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Fix type definitions to eliminate ts-expect-error.

The ts-expect-error comment indicates that errorMessageId and feedbackMessageId are not properly typed in the return value of sanitizeInputProps. This bypasses type safety and could mask future type errors.

Update the return type of sanitizeInputProps in useFormField.tsx to explicitly include these properties when they're in the keep array:

export const sanitizeInputProps = <K extends keyof ReturnType<typeof useFormField>>(
  obj: ReturnType<typeof useFormField>,
  keep?: K[],
): Omit<ReturnType<typeof useFormField>, 
  'radioOptions' | 'validatePassword' | 'hasPassedComplexity' | 'isFocused' | 
  'feedback' | 'feedbackType' | 'setHasPassedComplexity' | 'setWarning' | 
  'setSuccess' | 'setError' | 'setInfo' | 'errorMessageId' | 'feedbackMessageId' | 
  'fieldId' | 'label' | 'clearFeedback' | 'infoText' | 'debouncedFeedback' | 
  'ignorePasswordManager' | 'transformer'
> & Pick<ReturnType<typeof useFormField>, K extends keyof ReturnType<typeof useFormField> ? K : never> => {
  // implementation
}

Alternatively, consider using a simpler approach with proper type assertions where the dynamic behavior is actually needed.

// We can verify the currently visible element has aria-live="polite"
const allAriaLivePolite = container.querySelectorAll('[aria-live="polite"]');
// At least the success message should have aria-live="polite"
expect(allAriaLivePolite.length).toBeGreaterThanOrEqual(1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't that me strictly equal to one ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, good catch! 651f11b

Copy link

pkg-pr-new bot commented Oct 7, 2025

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@6914

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@6914

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@6914

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@6914

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@6914

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@6914

@clerk/elements

npm i https://pkg.pr.new/@clerk/elements@6914

@clerk/clerk-expo

npm i https://pkg.pr.new/@clerk/clerk-expo@6914

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@6914

@clerk/express

npm i https://pkg.pr.new/@clerk/express@6914

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@6914

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@6914

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@6914

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@6914

@clerk/clerk-react

npm i https://pkg.pr.new/@clerk/clerk-react@6914

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@6914

@clerk/remix

npm i https://pkg.pr.new/@clerk/remix@6914

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@6914

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@6914

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@6914

@clerk/themes

npm i https://pkg.pr.new/@clerk/themes@6914

@clerk/types

npm i https://pkg.pr.new/@clerk/types@6914

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@6914

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@6914

commit: dde3fd5

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/clerk-js/src/ui/elements/FormControl.tsx (1)

137-147: Prevent duplicate feedback IDs during cross-fade.

getElementProps assigns the same id to both slots even when shouldEnter is false. When a new message of the same type (e.g., another error) arrives, both rendered nodes momentarily share that id—one hidden, one live. Because aria-describedby resolves to the first matching id, assistive tech can end up reading the stale, hidden message. Please only apply the id when we actually render the active message (and skip it entirely if id is undefined) so the live region stays unique and screen readers follow the current feedback.

Also applies to: 172-195

📜 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.

📥 Commits

Reviewing files that changed from the base of the PR and between db1c3e0 and 651f11b.

📒 Files selected for processing (7)
  • packages/clerk-js/src/ui/elements/FieldControl.tsx (1 hunks)
  • packages/clerk-js/src/ui/elements/FormControl.tsx (5 hunks)
  • packages/clerk-js/src/ui/elements/__tests__/PlainInput.test.tsx (4 hunks)
  • packages/clerk-js/src/ui/primitives/FormErrorText.tsx (1 hunks)
  • packages/clerk-js/src/ui/primitives/FormInfoText.tsx (1 hunks)
  • packages/clerk-js/src/ui/primitives/Input.tsx (2 hunks)
  • packages/clerk-js/src/ui/primitives/hooks/useFormField.tsx (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/clerk-js/src/ui/primitives/FormInfoText.tsx
🧰 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/FormControl.tsx
  • packages/clerk-js/src/ui/elements/FieldControl.tsx
  • packages/clerk-js/src/ui/primitives/Input.tsx
  • packages/clerk-js/src/ui/primitives/FormErrorText.tsx
  • packages/clerk-js/src/ui/primitives/hooks/useFormField.tsx
  • 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/FormControl.tsx
  • packages/clerk-js/src/ui/elements/FieldControl.tsx
  • packages/clerk-js/src/ui/primitives/Input.tsx
  • packages/clerk-js/src/ui/primitives/FormErrorText.tsx
  • packages/clerk-js/src/ui/primitives/hooks/useFormField.tsx
  • 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/FormControl.tsx
  • packages/clerk-js/src/ui/elements/FieldControl.tsx
  • packages/clerk-js/src/ui/primitives/Input.tsx
  • packages/clerk-js/src/ui/primitives/FormErrorText.tsx
  • packages/clerk-js/src/ui/primitives/hooks/useFormField.tsx
  • 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/FormControl.tsx
  • packages/clerk-js/src/ui/elements/FieldControl.tsx
  • packages/clerk-js/src/ui/primitives/Input.tsx
  • packages/clerk-js/src/ui/primitives/FormErrorText.tsx
  • packages/clerk-js/src/ui/primitives/hooks/useFormField.tsx
  • 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/FormControl.tsx
  • packages/clerk-js/src/ui/elements/FieldControl.tsx
  • packages/clerk-js/src/ui/primitives/Input.tsx
  • packages/clerk-js/src/ui/primitives/FormErrorText.tsx
  • packages/clerk-js/src/ui/primitives/hooks/useFormField.tsx
  • 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
Avoid any type - prefer unknown when type is uncertain, then narrow with type guards
Use interface for object shapes that might be extended
Use type for unions, primitives, and computed types
Prefer readonly properties for immutable data structures
Use private for internal implementation details
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Prefer readonly for 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
Use const assertions for literal types: as const
Use satisfies operator 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 ...
No any types without justification
Proper error handling with typed errors
Consistent use of readonly for 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/FormControl.tsx
  • packages/clerk-js/src/ui/elements/FieldControl.tsx
  • packages/clerk-js/src/ui/primitives/Input.tsx
  • packages/clerk-js/src/ui/primitives/FormErrorText.tsx
  • packages/clerk-js/src/ui/primitives/hooks/useFormField.tsx
  • 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/FormControl.tsx
  • packages/clerk-js/src/ui/elements/FieldControl.tsx
  • packages/clerk-js/src/ui/primitives/Input.tsx
  • packages/clerk-js/src/ui/primitives/FormErrorText.tsx
  • packages/clerk-js/src/ui/primitives/hooks/useFormField.tsx
  • 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/FormControl.tsx
  • packages/clerk-js/src/ui/elements/FieldControl.tsx
  • packages/clerk-js/src/ui/primitives/Input.tsx
  • packages/clerk-js/src/ui/primitives/FormErrorText.tsx
  • packages/clerk-js/src/ui/primitives/hooks/useFormField.tsx
  • 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/FormControl.tsx
  • packages/clerk-js/src/ui/elements/FieldControl.tsx
  • packages/clerk-js/src/ui/primitives/Input.tsx
  • packages/clerk-js/src/ui/primitives/FormErrorText.tsx
  • packages/clerk-js/src/ui/primitives/hooks/useFormField.tsx
  • 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
**/*.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
🧬 Code graph analysis (1)
packages/clerk-js/src/ui/primitives/Input.tsx (1)
packages/clerk-js/src/ui/primitives/hooks/useFormField.tsx (1)
  • sanitizeInputProps (120-156)
⏰ 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). (30)
  • GitHub Check: Integration Tests (handshake:staging, chrome)
  • GitHub Check: Integration Tests (billing, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 15)
  • GitHub Check: Integration Tests (express, chrome)
  • GitHub Check: Integration Tests (machine, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 14)
  • GitHub Check: Integration Tests (nuxt, chrome)
  • GitHub Check: Integration Tests (react-router, chrome)
  • GitHub Check: Integration Tests (custom, chrome)
  • GitHub Check: Integration Tests (handshake, chrome)
  • GitHub Check: Integration Tests (localhost, chrome)
  • GitHub Check: Integration Tests (vue, chrome)
  • GitHub Check: Integration Tests (quickstart, chrome)
  • GitHub Check: Integration Tests (tanstack-react-router, chrome)
  • GitHub Check: Integration Tests (expo-web, chrome)
  • GitHub Check: Integration Tests (tanstack-react-start, chrome)
  • GitHub Check: Integration Tests (astro, chrome)
  • GitHub Check: Integration Tests (elements, chrome)
  • GitHub Check: Integration Tests (sessions:staging, chrome)
  • GitHub Check: Integration Tests (sessions, chrome)
  • GitHub Check: Integration Tests (generic, chrome)
  • GitHub Check: Integration Tests (ap-flows, chrome)
  • GitHub Check: Publish with pkg-pr-new
  • GitHub Check: Static analysis
  • GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
  • GitHub Check: Unit Tests (22, **)
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: semgrep/ci
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants