Skip to content

Conversation

jacekradko
Copy link
Member

@jacekradko jacekradko commented Oct 20, 2025

Description

When users visited /sign-in while already having an active session in multi-session mode, they saw the standard sign-in form with zero indication they were already authenticated.

Fixes: USER-3745

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

    • Multi-session apps now redirect users with an active session to the account selection screen (/choose).
    • Initiating "Add account" opens sign-in with a query flag and avoids redirect loops; direct visits that include the add-account flag are cleaned from the URL.
    • Single-session mode preserves single-account behavior (no redirect to account chooser).
  • Tests

    • Added unit and end-to-end tests covering multi- vs single-session redirects, account switcher behavior, add-account flow, and full sign-in/sign-out scenarios.

@vercel
Copy link

vercel bot commented Oct 20, 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 21, 2025 3:12pm

💡 Enable Vercel Agent with $100 free credit for automated AI reviews

@changeset-bot
Copy link

changeset-bot bot commented Oct 20, 2025

🦋 Changeset detected

Latest commit: 8290ce5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@clerk/clerk-js Patch
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 20, 2025

Walkthrough

Adds logic to SignInStart to detect active sessions in multi-session mode and redirect to /sign-in/choose; removes the __clerk_add_account URL param when present. Updates add-account navigation to append __clerk_add_account=1. Adds unit and integration tests and a changeset.

Changes

Cohort / File(s) Change Summary
SignInStart redirect
packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx
Adds an initialization guard ref and a useEffect that, when no organizationTicket, checks clerk.client?.signedInSessions and !authConfig.singleSessionMode; if active sessions exist navigates to 'choose' and cleans __clerk_add_account from the URL.
Unit tests: SignInStart
packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.test.tsx
Adds "Active session redirect" tests covering multi-session and single-session modes: expects redirect to choose when active sessions exist in multi-session mode, no redirect when zero sessions, and no redirect in single-session mode.
Integration tests: multi-session behavior
integration/tests/sign-in-active-session-redirect.test.ts
New Playwright tests asserting /sign-in redirects to /sign-in/choose with an active session, account switcher displays active session and "Add account", sign-in shown when no sessions, and no redirect loop when adding an account.
Integration tests: single-session mode
integration/tests/sign-in-single-session-mode.test.ts
New Playwright tests for single-session behavior: redirect to afterSignIn when active session exists, absence of account switcher, sign-in form when unauthenticated, and end-to-end sign-in/sign-out flow.
Add-account navigation update
packages/clerk-js/src/ui/components/UserButton/useMultisessionActions.tsx
handleAddAccountClicked now builds a sign-in URL (using opts.signInUrl or current location) with the correct origin, appends __clerk_add_account=1 as a query param, and navigates to that URL (keeps post-navigation delay).
Changeset
.changeset/kind-paws-swim.md
Adds a changeset noting the patch: detect active sessions in multi-session apps and redirect to /choose.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Browser
    participant SignInStart
    participant Clerk
    participant Router

    User->>Browser: GET /sign-in
    Browser->>SignInStart: mount
    SignInStart->>Clerk: read client.signedInSessions & authConfig
    Clerk-->>SignInStart: sessions list + config

    alt Multi-session AND active sessions
        Note right of SignInStart #e6f7ff: detect active sessions\nand not single-session
        SignInStart->>Router: navigate('choose')
        Router->>Browser: redirect to /sign-in/choose
        Browser->>User: shows account switcher
    else No active sessions OR single-session mode
        SignInStart->>Browser: render sign-in UI
        Browser->>User: shows sign-in form
    end
Loading
sequenceDiagram
    participant User
    participant UI
    participant useMultisessionActions
    participant Router

    User->>UI: Click "Add account"
    UI->>useMultisessionActions: handleAddAccountClicked(opts)
    Note right of useMultisessionActions #f0fff4: build URL with origin\nappend __clerk_add_account=1
    useMultisessionActions->>Router: navigate(builtUrl)
    Router->>User: loads /sign-in?...__clerk_add_account=1
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I hop toward /sign-in, nose a clue,
If many friends are logged in, I whisper "Choose."
I tuck a flag in the query seam,
Steer clear of loops and keep the flow clean.
Happy hops for tidy sign-in views 🌿

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "fix(clerk-js): Detect if user is signed in already" directly aligns with the main objective of this PR, which is to detect when users have active sessions in multi-session mode while visiting /sign-in. The title accurately summarizes the primary change—detecting existing authenticated sessions—and is concise and specific enough to convey meaningful information about the changeset. The implementation across the modified files (SignInStart.tsx, useMultisessionActions.tsx, and test files) consistently supports this central theme.
Linked Issues Check ✅ Passed The code changes comprehensively address all objectives from USER-3745. The PR detects active sessions in multi-session mode by adding initialization logic in SignInStart.tsx that checks for existing sessions and redirects to the choose route [USER-3745], preventing the standard sign-in form from displaying without indication of authentication. The modified handleAddAccountClicked in useMultisessionActions.tsx enables users to add additional accounts via the __clerk_add_account parameter. Extensive test coverage verifies both multi-session redirect behavior and single-session mode compliance, confirming the fix works as intended without breaking existing functionality.
Out of Scope Changes Check ✅ Passed All changes in this PR are directly scoped to the objectives of USER-3745. The modifications to SignInStart.tsx and useMultisessionActions.tsx implement the core session detection and redirect functionality. The test files (SignInStart.test.tsx, sign-in-active-session-redirect.test.ts, sign-in-single-session-mode.test.ts, and session-tasks-multi-session.test.ts) validate the new behavior for both multi-session and single-session modes, ensuring no regressions. The changeset entry documents the patch appropriately. No unrelated features or refactorings have been introduced.
✨ 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 fix/detect-multisession-already-signed-in

📜 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 e4e793f and 8290ce5.

📒 Files selected for processing (2)
  • integration/tests/session-tasks-multi-session.test.ts (1 hunks)
  • packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (12)
**/*.{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:

  • integration/tests/session-tasks-multi-session.test.ts
  • packages/clerk-js/src/ui/components/SignIn/SignInStart.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:

  • integration/tests/session-tasks-multi-session.test.ts
  • packages/clerk-js/src/ui/components/SignIn/SignInStart.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:

  • integration/tests/session-tasks-multi-session.test.ts
  • packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx
integration/**

📄 CodeRabbit inference engine (.cursor/rules/global.mdc)

Framework integration templates and E2E tests should be placed under the integration/ directory

Files:

  • integration/tests/session-tasks-multi-session.test.ts
integration/**/*

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

End-to-end tests and integration templates must be located in the 'integration/' directory.

Files:

  • integration/tests/session-tasks-multi-session.test.ts
integration/**/*.{test,spec}.{js,ts}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Integration tests should use Playwright.

Files:

  • integration/tests/session-tasks-multi-session.test.ts
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.

Files:

  • integration/tests/session-tasks-multi-session.test.ts
  • packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx
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/components/SignIn/SignInStart.tsx
packages/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/ui/components/SignIn/SignInStart.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/components/SignIn/SignInStart.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/components/SignIn/SignInStart.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/components/SignIn/SignInStart.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). (3)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (3)
packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx (2)

112-112: LGTM! Appropriate use of ref for one-time initialization.

The hasInitializedRef correctly tracks whether the account-switching initialization has run, preventing duplicate navigation or URL manipulation on subsequent re-renders.


185-213: Well-implemented session detection with proper guards.

This effect correctly addresses the past review comment's concern about the organization ticket race condition by including the organizationTicket guard at line 189. The implementation properly:

  • Prevents conflicts with the organization ticket flow by checking organizationTicket first
  • Ensures one-time execution using hasInitializedRef to avoid duplicate navigations
  • Cleanly removes the __clerk_add_account URL parameter without triggering navigation
  • Navigates to the account chooser when active sessions exist in multi-session mode

The dependencies list is appropriate, including organizationTicket to handle cases where the URL changes on re-render.

integration/tests/session-tasks-multi-session.test.ts (1)

64-80: Excellent test coverage for the new multi-session redirect flow.

These additions correctly validate the new behavior where users with active sessions are redirected to the account chooser (/sign-in/choose) before being able to add a new account. The test properly:

  • Waits for the redirect to /sign-in/choose after navigating to sign-in with an active session
  • Interacts with the "Add account" button to proceed
  • Waits for both the URL change to /sign-in$ and component visibility before continuing

The use of multiple wait conditions (URL, component mount, input visibility) ensures test stability and prevents race conditions.


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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 20, 2025

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

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

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

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

@clerk/types

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

@clerk/upgrade

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

@clerk/vue

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

commit: 8290ce5

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

📜 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 64d3135 and a546210.

📒 Files selected for processing (2)
  • packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx (1 hunks)
  • packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.test.tsx (1 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/components/SignIn/SignInStart.tsx
  • packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.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/components/SignIn/SignInStart.tsx
  • packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.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/components/SignIn/SignInStart.tsx
  • packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.test.tsx
packages/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx
  • packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.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/components/SignIn/SignInStart.tsx
  • packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.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/components/SignIn/SignInStart.tsx
  • packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.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/components/SignIn/SignInStart.tsx
  • packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.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/components/SignIn/SignInStart.tsx
  • packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.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/components/SignIn/SignInStart.tsx
  • packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.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/components/SignIn/__tests__/SignInStart.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/components/SignIn/__tests__/SignInStart.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/components/SignIn/__tests__/SignInStart.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/components/SignIn/__tests__/SignInStart.test.tsx
🧬 Code graph analysis (1)
packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.test.tsx (2)
packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx (1)
  • SignInStart (713-715)
packages/clerk-js/src/test/utils.ts (2)
  • waitFor (73-73)
  • screen (72-72)
⏰ 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: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx (1)

184-194: Confirm intended UX for adding new accounts in multi-session mode.

The unconditional redirect prevents users from accessing the sign-in form when they already have active sessions in multi-session mode. Ensure that the account switcher (the "choose" route) provides a clear path for users who explicitly want to sign in with a different account or add a new account.

If the account switcher doesn't have an "Add account" or "Sign in with different account" option that bypasses this redirect, users may be unable to add additional accounts in multi-session mode.

packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.test.tsx (1)

593-699: Excellent test coverage for the session redirect feature.

The test suite comprehensively covers all scenarios:

  • Multi-session mode with single and multiple active sessions (redirects)
  • Multi-session mode with no active sessions (no redirect)
  • Single-session mode with active session (no redirect)

The tests properly isolate each scenario by creating separate fixtures and correctly mock the signedInSessions state. The use of waitFor for async navigation assertions is appropriate.

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: 0

🧹 Nitpick comments (2)
packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.test.tsx (2)

674-701: Add component render verification for consistency.

This test verifies that navigation doesn't occur in single-session mode, but unlike the similar test at lines 651-670, it doesn't verify that the component actually rendered the sign-in form. This makes the test less robust—if the component crashed, the test would still pass.

Add a render verification after the waitFor block for consistency:

         await waitFor(
           () => {
             expect(fixtures.router.navigate).not.toHaveBeenCalledWith('choose');
           },
           { timeout: 100 },
         );
+
+        screen.getByText(/email address/i);
       });

607-611: Consider using a typed mock factory for sessions.

The as any type assertions are acceptable in tests but reduce type safety. For better maintainability, consider creating a typed session mock factory.

Example approach:

const createMockSession = (overrides: Partial<SessionResource> = {}): SessionResource => ({
  id: 'sess_default',
  status: 'active',
  user: fixtures.clerk.user,
  // ... other required properties with sensible defaults
  ...overrides,
} as SessionResource);

Then use:

vi.spyOn(fixtures.clerk.client, 'signedInSessions', 'get').mockReturnValue([
  createMockSession({ id: 'sess_123' }),
]);

Also applies to: 632-641, 684-688

📜 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 291e79f and cdbd2d8.

📒 Files selected for processing (1)
  • packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.test.tsx (1 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/components/SignIn/__tests__/SignInStart.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/components/SignIn/__tests__/SignInStart.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/components/SignIn/__tests__/SignInStart.test.tsx
packages/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.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/components/SignIn/__tests__/SignInStart.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/components/SignIn/__tests__/SignInStart.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/components/SignIn/__tests__/SignInStart.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/components/SignIn/__tests__/SignInStart.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/components/SignIn/__tests__/SignInStart.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/components/SignIn/__tests__/SignInStart.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/components/SignIn/__tests__/SignInStart.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/components/SignIn/__tests__/SignInStart.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/components/SignIn/__tests__/SignInStart.test.tsx
🧬 Code graph analysis (1)
packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.test.tsx (1)
packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx (1)
  • SignInStart (713-715)
⏰ 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)
  • GitHub Check: Build Packages
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (3)
packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.test.tsx (3)

596-619: Test coverage looks good.

The test correctly verifies that a user with one active session in multi-session mode is redirected to the account switcher.


621-649: Test correctly covers multiple active sessions.

The test verifies that multiple active sessions also trigger the redirect, which is an important edge case.


651-670: Well-designed negative test case.

Good practice to verify both that navigation didn't occur AND that the component rendered correctly (Line 669). This ensures the test isn't passing due to a component failure.

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 (2)
integration/tests/sign-in-active-session-redirect.test.ts (2)

7-9: Consider clarifying the test suite description.

The test suite description could explicitly mention "multi-session mode" to match the clarity of the single-session test suite and make it immediately clear what behavior is being tested.

Apply this diff to improve clarity:

-  'sign in redirect with active session @generic @nextjs',
+  'sign in redirect with active session in multi-session mode @generic @nextjs',

64-72: Consider extracting duplicated test logic.

This test is nearly identical to the "shows sign-in form when no active session" test in sign-in-single-session-mode.test.ts (lines 54-62). While testing the no-session scenario in both modes is valuable, the identical implementation could be extracted to a shared test utility function to reduce duplication.

📜 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 cdbd2d8 and 71d2e6a.

📒 Files selected for processing (2)
  • integration/tests/sign-in-active-session-redirect.test.ts (1 hunks)
  • integration/tests/sign-in-single-session-mode.test.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
**/*.{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:

  • integration/tests/sign-in-active-session-redirect.test.ts
  • integration/tests/sign-in-single-session-mode.test.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • integration/tests/sign-in-active-session-redirect.test.ts
  • integration/tests/sign-in-single-session-mode.test.ts
**/*.{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:

  • integration/tests/sign-in-active-session-redirect.test.ts
  • integration/tests/sign-in-single-session-mode.test.ts
integration/**

📄 CodeRabbit inference engine (.cursor/rules/global.mdc)

Framework integration templates and E2E tests should be placed under the integration/ directory

Files:

  • integration/tests/sign-in-active-session-redirect.test.ts
  • integration/tests/sign-in-single-session-mode.test.ts
integration/**/*

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

End-to-end tests and integration templates must be located in the 'integration/' directory.

Files:

  • integration/tests/sign-in-active-session-redirect.test.ts
  • integration/tests/sign-in-single-session-mode.test.ts
integration/**/*.{test,spec}.{js,ts}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Integration tests should use Playwright.

Files:

  • integration/tests/sign-in-active-session-redirect.test.ts
  • integration/tests/sign-in-single-session-mode.test.ts
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.

Files:

  • integration/tests/sign-in-active-session-redirect.test.ts
  • integration/tests/sign-in-single-session-mode.test.ts
🧬 Code graph analysis (2)
integration/tests/sign-in-active-session-redirect.test.ts (2)
integration/testUtils/index.ts (1)
  • createTestUtils (24-86)
integration/presets/index.ts (1)
  • appConfigs (15-32)
integration/tests/sign-in-single-session-mode.test.ts (2)
integration/testUtils/index.ts (2)
  • testAgainstRunningApps (88-88)
  • createTestUtils (24-86)
integration/presets/index.ts (1)
  • appConfigs (15-32)
⏰ 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). (22)
  • GitHub Check: Integration Tests (astro, chrome)
  • GitHub Check: Integration Tests (expo-web, chrome)
  • GitHub Check: Integration Tests (tanstack-react-start, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 14)
  • GitHub Check: Integration Tests (react-router, chrome)
  • GitHub Check: Integration Tests (handshake:staging, chrome)
  • GitHub Check: Integration Tests (ap-flows, chrome)
  • GitHub Check: Integration Tests (sessions, chrome)
  • GitHub Check: Integration Tests (sessions:staging, chrome)
  • GitHub Check: Integration Tests (elements, chrome)
  • GitHub Check: Integration Tests (handshake, chrome)
  • GitHub Check: Integration Tests (express, chrome)
  • GitHub Check: Integration Tests (localhost, chrome)
  • GitHub Check: Integration Tests (quickstart, chrome)
  • GitHub Check: Unit Tests (22, **)
  • GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
  • GitHub Check: Publish with pkg-pr-new
  • GitHub Check: Static analysis
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (4)
integration/tests/sign-in-single-session-mode.test.ts (3)

1-9: LGTM!

The imports follow TypeScript best practices with type-only imports, and the test suite setup properly configures the environment with email codes.


10-25: LGTM!

The serial test configuration is appropriate for session-dependent tests, and the setup/teardown properly manages the fake user lifecycle.


27-73: LGTM!

The test cases comprehensively cover single-session mode behavior including redirect logic, account switcher absence, and normal sign-in flows.

integration/tests/sign-in-active-session-redirect.test.ts (1)

34-62: LGTM!

The tests properly verify multi-session mode behavior including the redirect to the account switcher and the presence of the "Add account" option.

@vercel
Copy link

vercel bot commented Oct 20, 2025

Deployment failed with the following error:

Failed to create deployment for team_WkGqQVj7eL8Pmap8W5wWH515 in project prj_NmBduNLVSIsOYSHqbIi88GvHAxgD: FetchError: request to https://76.76.21.112/v13/now/deployments?ownerId=team_WkGqQVj7eL8Pmap8W5wWH515&projectId=prj_NmBduNLVSIsOYSHqbIi88GvHAxgD&skipAutoDetectionConfirmation=1&teamId=team_WkGqQVj7eL8Pmap8W5wWH515&traceCarrier=%7B%22ot-baggage-webhookAt%22%3A%221760990678005%22%2C%22ot-baggage-senderUsername%22%3A%22gh.jacekradko%22%2C%22baggage%22%3A%22webhookAt%3D1760990678005%2CsenderUsername%3Dgh.jacekradko%22%2C%22x-datadog-trace-id%22%3A%222268846015097514163%22%2C%22x-datadog-parent-id%22%3A%227165909533829195054%22%2C%22x-datadog-sampling-priority%22%3A%222%22%2C%22x-datadog-tags%22%3A%22_dd.p.tid%3D68f695d600000000%2C_dd.p.dm%3D-3%22%2C%22traceparent%22%3A%2200-68f695d6000000001f7c8f6e0bf2a8b3-63726cc12079652e-01%22%2C%22tracestate%22%3A%22dd%3Dt.tid%3A68f695d600000000%3Bt.dm%3A-3%3Bs%3A2%3Bp%3A63726cc12079652e%22%7D failed, reason: socket hang up

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: 0

♻️ Duplicate comments (1)
packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx (1)

184-209: Good: org-ticket guard resolves the navigation race.

The early return when organizationTicket exists avoids conflicts with the ticket flow. Looks correct.

🧹 Nitpick comments (5)
packages/clerk-js/src/ui/components/UserButton/useMultisessionActions.tsx (1)

101-106: Unify fallback URL and avoid magic string for the query key.

  • Use displayConfig.signInUrl as the fallback (keeps consistency with handleSessionClicked).
  • Extract the query key to a constant to avoid typos and enable reuse.
   const handleAddAccountClicked = () => {
-    const url = new URL(opts.signInUrl || window.location.href, window.location.origin);
-    url.searchParams.set('__clerk_add_account', '1');
+    const ADD_ACCOUNT_PARAM = '__clerk_add_account' as const;
+    const target = opts.signInUrl ?? displayConfig.signInUrl ?? window.location.href;
+    const url = new URL(target, window.location.origin);
+    url.searchParams.set(ADD_ACCOUNT_PARAM, '1');
     windowNavigate(url.toString());
     return sleep(2000);
   };
packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx (2)

188-201: Edge case: clean "__clerk_add_account" even when an organization ticket is present.

If both __clerk_ticket and __clerk_add_account are in the URL, the early return skips add-account cleanup, leaving stale params.

   useEffect(() => {
-    if (organizationTicket) {
-      return;
-    }
+    // Always clean __clerk_add_account first
+    const urlParams = new URLSearchParams(window.location.search);
+    const isAddingAccount = urlParams.has('__clerk_add_account');
+    if (isAddingAccount) {
+      urlParams.delete('__clerk_add_account');
+      const newSearch = urlParams.toString();
+      const newUrl = window.location.pathname + (newSearch ? `?${newSearch}` : '');
+      window.history.replaceState({}, '', newUrl);
+      // Continue with other flows after cleanup
+    }
+
+    if (organizationTicket) {
+      return;
+    }
-
-    const urlParams = new URLSearchParams(window.location.search);
-    const isAddingAccount = urlParams.has('__clerk_add_account');
-
-    if (isAddingAccount) {
-      urlParams.delete('__clerk_add_account');
-      const newSearch = urlParams.toString();
-      const newUrl = window.location.pathname + (newSearch ? `?${newSearch}` : '');
-      window.history.replaceState({}, '', newUrl);
-      return;
-    }

192-201: Optional: reuse a shared helper/constant for "__clerk_add_account".

For consistency with getClerkQueryParam/removeClerkQueryParam and to avoid typos, consider a small util (e.g., getClerkAddAccountParam/removeClerkAddAccountParam) or at least a local const.

packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.test.tsx (1)

594-702: Nice coverage for multi- vs single-session redirect. Add two focused tests.

  • Add a unit test that sets ?__clerk_add_account=1 and verifies no redirect to 'choose' and that history.replaceState removed the param.
  • Add a unit test where organizationTicket is present and signedInSessions > 0 to assert no redirect to 'choose' (org-ticket flow takes precedence).

I can draft the two test cases if helpful.

integration/tests/sign-in-active-session-redirect.test.ts (1)

67-93: Reduce flakiness and assert URL cleanup after "Add account".

  • Instead of two waitForTimeout(500) calls to detect loops, assert the URL is exactly /sign-in (and not /sign-in/choose) for a reasonable duration via expect(page).toHaveURL.
  • Also assert that __clerk_add_account is removed from the URL after landing on /sign-in.
-      await u.page.waitForTimeout(500);
-      const currentUrl = u.page.url();
-      await u.page.waitForTimeout(500);
-      const urlAfterWait = u.page.url();
-
-      if (currentUrl !== urlAfterWait) {
-        throw new Error(`URL changed from ${currentUrl} to ${urlAfterWait}, indicating a redirect loop`);
-      }
+      await expect(u.page).toHaveURL(/\/sign-in$/);
+      expect(u.page.url()).not.toMatch(/__clerk_add_account=/);
+      // Ensure we did not bounce back to /choose
+      await expect(u.page).not.toHaveURL(/\/sign-in\/choose/);
📜 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 670d98c and a027d82.

📒 Files selected for processing (5)
  • integration/tests/sign-in-active-session-redirect.test.ts (1 hunks)
  • integration/tests/sign-in-single-session-mode.test.ts (1 hunks)
  • packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx (1 hunks)
  • packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.test.tsx (1 hunks)
  • packages/clerk-js/src/ui/components/UserButton/useMultisessionActions.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • integration/tests/sign-in-single-session-mode.test.ts
🧰 Additional context used
📓 Path-based instructions (16)
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/components/SignIn/SignInStart.tsx
  • packages/clerk-js/src/ui/components/UserButton/useMultisessionActions.tsx
  • packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.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/components/SignIn/SignInStart.tsx
  • packages/clerk-js/src/ui/components/UserButton/useMultisessionActions.tsx
  • packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.test.tsx
  • integration/tests/sign-in-active-session-redirect.test.ts
**/*.{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/components/SignIn/SignInStart.tsx
  • packages/clerk-js/src/ui/components/UserButton/useMultisessionActions.tsx
  • packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.test.tsx
  • integration/tests/sign-in-active-session-redirect.test.ts
packages/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx
  • packages/clerk-js/src/ui/components/UserButton/useMultisessionActions.tsx
  • packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.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/components/SignIn/SignInStart.tsx
  • packages/clerk-js/src/ui/components/UserButton/useMultisessionActions.tsx
  • packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.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/components/SignIn/SignInStart.tsx
  • packages/clerk-js/src/ui/components/UserButton/useMultisessionActions.tsx
  • packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.test.tsx
  • integration/tests/sign-in-active-session-redirect.test.ts
**/*.{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/components/SignIn/SignInStart.tsx
  • packages/clerk-js/src/ui/components/UserButton/useMultisessionActions.tsx
  • packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.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/components/SignIn/SignInStart.tsx
  • packages/clerk-js/src/ui/components/UserButton/useMultisessionActions.tsx
  • packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.test.tsx
  • integration/tests/sign-in-active-session-redirect.test.ts
**/*.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/components/SignIn/SignInStart.tsx
  • packages/clerk-js/src/ui/components/UserButton/useMultisessionActions.tsx
  • packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.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/components/SignIn/__tests__/SignInStart.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/components/SignIn/__tests__/SignInStart.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/components/SignIn/__tests__/SignInStart.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/components/SignIn/__tests__/SignInStart.test.tsx
integration/**

📄 CodeRabbit inference engine (.cursor/rules/global.mdc)

Framework integration templates and E2E tests should be placed under the integration/ directory

Files:

  • integration/tests/sign-in-active-session-redirect.test.ts
integration/**/*

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

End-to-end tests and integration templates must be located in the 'integration/' directory.

Files:

  • integration/tests/sign-in-active-session-redirect.test.ts
integration/**/*.{test,spec}.{js,ts}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Integration tests should use Playwright.

Files:

  • integration/tests/sign-in-active-session-redirect.test.ts
🧬 Code graph analysis (2)
packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.test.tsx (1)
packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx (1)
  • SignInStart (728-730)
integration/tests/sign-in-active-session-redirect.test.ts (2)
integration/testUtils/index.ts (1)
  • createTestUtils (24-86)
integration/presets/index.ts (1)
  • appConfigs (15-32)
⏰ 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)
  • GitHub Check: Build Packages
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan

@Ephem
Copy link

Ephem commented Oct 21, 2025

!snapshot

1 similar comment
@octoper
Copy link
Member

octoper commented Oct 21, 2025

!snapshot

@clerk-cookie
Copy link
Collaborator

Hey @octoper - the snapshot version command generated the following package versions:

Package Version
@clerk/agent-toolkit 0.1.43-snapshot.v20251021095452
@clerk/astro 2.14.1-snapshot.v20251021095452
@clerk/backend 2.18.4-snapshot.v20251021095452
@clerk/chrome-extension 2.7.8-snapshot.v20251021095452
@clerk/clerk-js 5.102.1-snapshot.v20251021095452
@clerk/elements 0.23.74-snapshot.v20251021095452
@clerk/clerk-expo 2.17.1-snapshot.v20251021095452
@clerk/expo-passkeys 0.4.11-snapshot.v20251021095452
@clerk/express 1.7.42-snapshot.v20251021095452
@clerk/fastify 2.4.42-snapshot.v20251021095452
@clerk/localizations 3.26.3-snapshot.v20251021095452
@clerk/nextjs 6.33.8-snapshot.v20251021095452
@clerk/nuxt 1.11.1-snapshot.v20251021095452
@clerk/clerk-react 5.53.3-snapshot.v20251021095452
@clerk/react-router 2.1.5-snapshot.v20251021095452
@clerk/remix 4.13.8-snapshot.v20251021095452
@clerk/shared 3.28.3-snapshot.v20251021095452
@clerk/tanstack-react-start 0.26.4-snapshot.v20251021095452
@clerk/testing 1.13.8-snapshot.v20251021095452
@clerk/themes 2.4.29-snapshot.v20251021095452
@clerk/types 4.95.1-snapshot.v20251021095452
@clerk/vue 1.14.8-snapshot.v20251021095452

Tip: Use the snippet copy button below to quickly install the required packages.
@clerk/agent-toolkit

npm i @clerk/[email protected] --save-exact

@clerk/astro

npm i @clerk/[email protected] --save-exact

@clerk/backend

npm i @clerk/[email protected] --save-exact

@clerk/chrome-extension

npm i @clerk/[email protected] --save-exact

@clerk/clerk-js

npm i @clerk/[email protected] --save-exact

@clerk/elements

npm i @clerk/[email protected] --save-exact

@clerk/clerk-expo

npm i @clerk/[email protected] --save-exact

@clerk/expo-passkeys

npm i @clerk/[email protected] --save-exact

@clerk/express

npm i @clerk/[email protected] --save-exact

@clerk/fastify

npm i @clerk/[email protected] --save-exact

@clerk/localizations

npm i @clerk/[email protected] --save-exact

@clerk/nextjs

npm i @clerk/[email protected] --save-exact

@clerk/nuxt

npm i @clerk/[email protected] --save-exact

@clerk/clerk-react

npm i @clerk/[email protected] --save-exact

@clerk/react-router

npm i @clerk/[email protected] --save-exact

@clerk/remix

npm i @clerk/[email protected] --save-exact

@clerk/shared

npm i @clerk/[email protected] --save-exact

@clerk/tanstack-react-start

npm i @clerk/[email protected] --save-exact

@clerk/testing

npm i @clerk/[email protected] --save-exact

@clerk/themes

npm i @clerk/[email protected] --save-exact

@clerk/types

npm i @clerk/[email protected] --save-exact

@clerk/vue

npm i @clerk/[email protected] --save-exact

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants