feat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n) - #7011

Merged
guilherme6191 merged 6 commits into
mainfrom
guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib
Oct 17, 2025
Merged

feat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n)#7011
guilherme6191 merged 6 commits into
mainfrom
guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib

Conversation

@guilherme6191

@guilherme6191guilherme6191 commented Oct 16, 2025

Copy link
Copy Markdown
Contributor

Description

This PR adds auto detection of browser locale (navigator.language) and sends that to sign-in flow. This is similar to the behavior implemented for the sign-up (#6915), but does not expose locale in the API to reduce noise/complexity at sign-in for now.

For extra context: this is a change where we'll be storing users preferred language from the browser, and C1s can update via BAPI (later on via dashboard and AIOs) so we can send localized templates. The whole feature is behind a FF and we're rolling out only for Spark (new customer implementing Clerk).

https://linear.app/clerk/issue/USER-3712/detect-and-send-locale-in-sign-ins-js-lib

Note: needs https://github.com/clerk/clerk_go/pull/14182 released

Checklist

Type of change

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

Summary by CodeRabbit

  • New Features

    • Sign-in flow now detects and automatically sends the browser locale to improve localization during authentication.
  • Tests

    • Added tests verifying locale is included when present and omitted when absent.
    • Test setup updated for a predictable navigator.language and centralized mock/cleanup to stabilize sign-in test suites.

@changeset-bot

changeset-botBot commented Oct 16, 2025

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c781372

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

This PR includes changesets to release 3 packages
NameType
@clerk/clerk-jsPatch
@clerk/chrome-extensionPatch
@clerk/clerk-expoPatch

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

@vercel

vercelBot commented Oct 16, 2025

Copy link
Copy Markdown

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

ProjectDeploymentPreviewCommentsUpdated (UTC)
clerk-js-sandboxReadyReadyPreviewCommentOct 17, 2025 4:21pm

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

@coderabbitai

coderabbitaiBot commented Oct 16, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Adds browser locale detection to the @clerk/clerk-js sign-in flow by calling getBrowserLocale() and conditionally including the locale in sign-in request bodies; if no locale is detected, requests omit the locale.

Changes

Cohort / File(s)Summary
Changeset documentation
​.changeset/quick-kings-rescue.md
Patch release entry noting addition of browser locale to sign-in flow.
Sign-in implementation
packages/clerk-js/src/core/resources/SignIn.ts
Computes locale via getBrowserLocale() and conditionally injects it into request bodies for SignIn.create, SignInFuture._create, and SignInFuture.password.
Sign-in tests
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
Adds tests asserting locale is included when navigator.language is set and excluded when empty; centralizes mock setup via beforeAll and resets mocks/unstubs in afterEach.
Test environment setup
packages/clerk-js/vitest.setup.mts
Sets window.navigator.language to an empty string ('') in the Vitest/jsdom setup.

Sequence Diagram(s)

sequenceDiagram
participant User
participant Browser
participant SignIn
participant Server
User->>SignIn: start sign-in (create / password)
SignIn->>Browser: getBrowserLocale()
alt locale detected
Browser-->>SignIn: "en-US" (example)
Note right of SignIn: include `locale` in request body
else locale not detected
Browser-->>SignIn: "" / undefined
Note right of SignIn: omit `locale` from request body
end
SignIn->>Server: POST /sign-in (body with/without locale)
Server-->>SignIn: response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I sniffed the browser breeze and found a clue,
I tucked the locale in the sign-in stew,
If silence whispered, I hopped away light,
The flow went on, tidy and right,
A tiny hop toward doing it true.

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title Check✅ PassedThe pull request title "feat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n)" is highly specific and accurately summarizes the main changes in the PR. It clearly communicates that the feature detects browser locale and sends it during sign-in, which aligns with all modifications across SignIn.ts, tests, and test setup. The title is concise, follows conventional commit formatting, and avoids vague terminology, making it immediately clear to reviewers what the core change accomplishes.
Linked Issues Check✅ PassedThe code changes fully satisfy the three primary objectives from USER-3712: locale detection from the browser is implemented via getBrowserLocale() [USER-3712], sending to the FAPI sign-in flow is accomplished by merging locale into the request body in SignIn.ts [USER-3712], and conditional sending without error handling is correctly implemented by only including locale when it is truthy [USER-3712]. The test suite validates both conditions—inclusion when navigator.language is set and exclusion when empty—confirming the implementation matches the requirements.
Out of Scope Changes Check✅ PassedAll changes in the pull request are directly related to the USER-3712 objective of detecting and sending browser locale during sign-in. The modifications to SignIn.ts implement the core feature, the test additions in SignIn.test.ts validate the locale detection and transmission, the changeset documents the new capability, and the vitest setup change provides test infrastructure support by mocking navigator.language. No unrelated refactoring, cleanup, or out-of-scope modifications are present.
Docstring Coverage✅ PassedNo 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 guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib

📜 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 f500017 and c781372.

📒 Files selected for processing (1)
  • packages/clerk-js/src/core/resources/SignIn.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/clerk-js/src/core/resources/SignIn.ts
⏰ 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

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

@pkg-pr-new

pkg-pr-newBot commented Oct 16, 2025

Copy link
Copy Markdown

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

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

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

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

@clerk/types

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

@clerk/upgrade

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

@clerk/vue

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

commit: c781372

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

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 160dc93 and 231a103.

📒 Files selected for processing (4)
  • .changeset/quick-kings-rescue.md (1 hunks)
  • packages/clerk-js/src/core/resources/SignIn.ts (4 hunks)
  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1 hunks)
  • packages/clerk-js/vitest.setup.mts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (10)
.changeset/**

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

Automated releases must use Changesets.

Files:

  • .changeset/quick-kings-rescue.md
**/*.{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/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.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/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
packages/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
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/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
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/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
**/__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/core/resources/__tests__/SignIn.test.ts
🧬 Code graph analysis (2)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)
packages/clerk-js/src/core/resources/SignIn.ts (1)
  • SignIn (99-556)
packages/clerk-js/src/core/resources/SignIn.ts (2)
packages/clerk-js/src/core/resources/SignUp.ts (1)
  • locale (650-652)
packages/clerk-js/src/utils/locale.ts (1)
  • getBrowserLocale (11-28)
⏰ 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). (2)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan


throw new Error('Unexpected call to BaseResource._fetch');
beforeAll(() => {
const signInCreatedJSON = {

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

with new tests and mocks, this was source of failing tests. So I just added moved the into the beforeAll function so we can have more control over order and scope

@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

since there is no change (even backwards compatible) to the sdk api for users, I think we have a patch here -- open to make it a minor as well

@guilherme6191guilherme6191 changed the title feat(i18n): at sign-in, detect locale from browser and send it to FAPI if existsfeat(i18n): At sign-in, detect locale from browser and send it to FAPI if existsOct 16, 2025
@guilherme6191guilherme6191 changed the title feat(i18n): At sign-in, detect locale from browser and send it to FAPI if existsfeat(i18n): Detect locale from browser and send it to FAPI if exists during sign-inOct 16, 2025
@guilherme6191

Copy link
Copy Markdown
ContributorAuthor

Note: I've labeled to do not merge for now as we need FAPI changes released - integration tests should fail because of that too.

return this._basePost({
path: this.pathRoot,
body: params,
body: { ...params, ...(locale ? { locale } : {}) },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe this order should be reversed, as we want to prefer the provided locale from params over the auto-detected one.

@guilherme6191guilherme6191Oct 16, 2025

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

@dstaley, good call. I'm updating the code as it's applicable in case we expose locale as a param as well, which is not the case now.

For now we're not exposing the locale to the sign-in API. We initially think that could add complexity for users and we'll revisit the DX if we expose it. It's available in sign-up as that's more appropriate there. Let me know if that makes sense.

FYI the functionality is going to be behind a FF too.

Comment thread.changeset/quick-kings-rescue.md Outdated
'@clerk/clerk-js': patch
---

Add browser locale to sign-in flow

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Add browser locale to sign-in flow
Add support for automatically sending the browser locale during the sign-in flow

@guilherme6191guilherme6191 changed the title feat(i18n): Detect locale from browser and send it to FAPI if exists during sign-infeat(clerk-js, i18n): Detect locale from browser and send it to FAPI if exists during sign-inOct 16, 2025
@guilherme6191
guilherme6191force-pushed the guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib branch from 7e714c7 to f500017CompareOctober 17, 2025 14:01

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

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 (1)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)

63-93: Consider adding cleanup for consistency.

The centralized mock setup in beforeAll is a good refactor. However, for consistency with the signIn.create suite and to prevent potential cross-suite pollution, consider adding an afterAll or afterEach to clear mocks after the SignInFuture tests complete.

 beforeAll(() => {
...
});
++ afterAll(() => {+ vi.clearAllMocks();+ });
it('should select correct first factor by email address', async () => {
📜 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 7e714c7 and f500017.

📒 Files selected for processing (4)
  • .changeset/quick-kings-rescue.md (1 hunks)
  • packages/clerk-js/src/core/resources/SignIn.ts (4 hunks)
  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1 hunks)
  • packages/clerk-js/vitest.setup.mts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • .changeset/quick-kings-rescue.md
  • packages/clerk-js/vitest.setup.mts
  • packages/clerk-js/src/core/resources/SignIn.ts
🧰 Additional context used
📓 Path-based instructions (9)
**/*.{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/core/resources/__tests__/SignIn.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/core/resources/__tests__/SignIn.test.ts
packages/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
**/__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/core/resources/__tests__/SignIn.test.ts
🧬 Code graph analysis (1)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)
packages/clerk-js/src/core/resources/SignIn.ts (1)
  • SignIn (99-556)
⏰ 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). (27)
  • GitHub Check: Integration Tests (billing, chrome)
  • GitHub Check: Integration Tests (machine, chrome)
  • GitHub Check: Integration Tests (custom, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 14)
  • GitHub Check: Integration Tests (handshake, chrome)
  • GitHub Check: Integration Tests (nuxt, chrome)
  • GitHub Check: Integration Tests (vue, chrome)
  • GitHub Check: Integration Tests (react-router, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 15)
  • GitHub Check: Integration Tests (sessions, chrome)
  • GitHub Check: Integration Tests (express, chrome)
  • GitHub Check: Integration Tests (astro, chrome)
  • GitHub Check: Integration Tests (sessions:staging, chrome)
  • GitHub Check: Integration Tests (tanstack-react-start, chrome)
  • GitHub Check: Integration Tests (localhost, chrome)
  • GitHub Check: Integration Tests (expo-web, chrome)
  • GitHub Check: Integration Tests (ap-flows, chrome)
  • GitHub Check: Integration Tests (handshake:staging, chrome)
  • GitHub Check: Integration Tests (quickstart, chrome)
  • GitHub Check: Integration Tests (elements, chrome)
  • GitHub Check: Integration Tests (generic, chrome)
  • GitHub Check: Static analysis
  • GitHub Check: Publish with pkg-pr-new
  • GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
  • GitHub Check: Unit Tests (22, **)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (1)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)

1-1: LGTM! Well-structured test suite for locale behavior.

The new test suite properly validates that:

  • Locale is included in the request body when navigator.language is set (test 1)
  • Locale is excluded when navigator.language is empty (test 2)

The cleanup in afterEach correctly addresses the past review concern about stubbed globals persisting across tests.

Also applies to: 7-59

@guilherme6191guilherme6191 changed the title feat(clerk-js, i18n): Detect locale from browser and send it to FAPI if exists during sign-infeat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n)Oct 17, 2025
Comment threadpackages/clerk-js/src/core/resources/SignIn.ts Outdated
Comment threadpackages/clerk-js/src/core/resources/SignIn.ts Outdated
@guilherme6191
guilherme6191 merged commit 6503405 into mainOct 17, 2025
41 checks passed
@guilherme6191
guilherme6191 deleted the guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib branch October 17, 2025 16:34
NicolasLopes7 pushed a commit that referenced this pull request Oct 23, 2025
Sign up for freeto 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

@guilherme6191@tmilewski@dstaley@clerk-cookie
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

feat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n) - #7011

Merged
guilherme6191 merged 6 commits into
mainfrom
guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib
Oct 17, 2025
Merged

feat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n)#7011
guilherme6191 merged 6 commits into
mainfrom
guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib

Conversation

@guilherme6191

@guilherme6191guilherme6191 commented Oct 16, 2025

Copy link
Copy Markdown
Contributor

Description

This PR adds auto detection of browser locale (navigator.language) and sends that to sign-in flow. This is similar to the behavior implemented for the sign-up (#6915), but does not expose locale in the API to reduce noise/complexity at sign-in for now.

For extra context: this is a change where we'll be storing users preferred language from the browser, and C1s can update via BAPI (later on via dashboard and AIOs) so we can send localized templates. The whole feature is behind a FF and we're rolling out only for Spark (new customer implementing Clerk).

https://linear.app/clerk/issue/USER-3712/detect-and-send-locale-in-sign-ins-js-lib

Note: needs https://github.com/clerk/clerk_go/pull/14182 released

Checklist

Type of change

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

Summary by CodeRabbit

  • New Features

    • Sign-in flow now detects and automatically sends the browser locale to improve localization during authentication.
  • Tests

    • Added tests verifying locale is included when present and omitted when absent.
    • Test setup updated for a predictable navigator.language and centralized mock/cleanup to stabilize sign-in test suites.

@changeset-bot

changeset-botBot commented Oct 16, 2025

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c781372

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

This PR includes changesets to release 3 packages
NameType
@clerk/clerk-jsPatch
@clerk/chrome-extensionPatch
@clerk/clerk-expoPatch

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

@vercel

vercelBot commented Oct 16, 2025

Copy link
Copy Markdown

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

ProjectDeploymentPreviewCommentsUpdated (UTC)
clerk-js-sandboxReadyReadyPreviewCommentOct 17, 2025 4:21pm

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

@coderabbitai

coderabbitaiBot commented Oct 16, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Adds browser locale detection to the @clerk/clerk-js sign-in flow by calling getBrowserLocale() and conditionally including the locale in sign-in request bodies; if no locale is detected, requests omit the locale.

Changes

Cohort / File(s)Summary
Changeset documentation
​.changeset/quick-kings-rescue.md
Patch release entry noting addition of browser locale to sign-in flow.
Sign-in implementation
packages/clerk-js/src/core/resources/SignIn.ts
Computes locale via getBrowserLocale() and conditionally injects it into request bodies for SignIn.create, SignInFuture._create, and SignInFuture.password.
Sign-in tests
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
Adds tests asserting locale is included when navigator.language is set and excluded when empty; centralizes mock setup via beforeAll and resets mocks/unstubs in afterEach.
Test environment setup
packages/clerk-js/vitest.setup.mts
Sets window.navigator.language to an empty string ('') in the Vitest/jsdom setup.

Sequence Diagram(s)

sequenceDiagram
participant User
participant Browser
participant SignIn
participant Server
User->>SignIn: start sign-in (create / password)
SignIn->>Browser: getBrowserLocale()
alt locale detected
Browser-->>SignIn: "en-US" (example)
Note right of SignIn: include `locale` in request body
else locale not detected
Browser-->>SignIn: "" / undefined
Note right of SignIn: omit `locale` from request body
end
SignIn->>Server: POST /sign-in (body with/without locale)
Server-->>SignIn: response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I sniffed the browser breeze and found a clue,
I tucked the locale in the sign-in stew,
If silence whispered, I hopped away light,
The flow went on, tidy and right,
A tiny hop toward doing it true.

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title Check✅ PassedThe pull request title "feat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n)" is highly specific and accurately summarizes the main changes in the PR. It clearly communicates that the feature detects browser locale and sends it during sign-in, which aligns with all modifications across SignIn.ts, tests, and test setup. The title is concise, follows conventional commit formatting, and avoids vague terminology, making it immediately clear to reviewers what the core change accomplishes.
Linked Issues Check✅ PassedThe code changes fully satisfy the three primary objectives from USER-3712: locale detection from the browser is implemented via getBrowserLocale() [USER-3712], sending to the FAPI sign-in flow is accomplished by merging locale into the request body in SignIn.ts [USER-3712], and conditional sending without error handling is correctly implemented by only including locale when it is truthy [USER-3712]. The test suite validates both conditions—inclusion when navigator.language is set and exclusion when empty—confirming the implementation matches the requirements.
Out of Scope Changes Check✅ PassedAll changes in the pull request are directly related to the USER-3712 objective of detecting and sending browser locale during sign-in. The modifications to SignIn.ts implement the core feature, the test additions in SignIn.test.ts validate the locale detection and transmission, the changeset documents the new capability, and the vitest setup change provides test infrastructure support by mocking navigator.language. No unrelated refactoring, cleanup, or out-of-scope modifications are present.
Docstring Coverage✅ PassedNo 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 guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib

📜 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 f500017 and c781372.

📒 Files selected for processing (1)
  • packages/clerk-js/src/core/resources/SignIn.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/clerk-js/src/core/resources/SignIn.ts
⏰ 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

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

@pkg-pr-new

pkg-pr-newBot commented Oct 16, 2025

Copy link
Copy Markdown

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

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

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

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

@clerk/types

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

@clerk/upgrade

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

@clerk/vue

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

commit: c781372

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

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 160dc93 and 231a103.

📒 Files selected for processing (4)
  • .changeset/quick-kings-rescue.md (1 hunks)
  • packages/clerk-js/src/core/resources/SignIn.ts (4 hunks)
  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1 hunks)
  • packages/clerk-js/vitest.setup.mts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (10)
.changeset/**

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

Automated releases must use Changesets.

Files:

  • .changeset/quick-kings-rescue.md
**/*.{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/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.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/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
packages/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
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/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
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/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
**/__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/core/resources/__tests__/SignIn.test.ts
🧬 Code graph analysis (2)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)
packages/clerk-js/src/core/resources/SignIn.ts (1)
  • SignIn (99-556)
packages/clerk-js/src/core/resources/SignIn.ts (2)
packages/clerk-js/src/core/resources/SignUp.ts (1)
  • locale (650-652)
packages/clerk-js/src/utils/locale.ts (1)
  • getBrowserLocale (11-28)
⏰ 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). (2)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan


throw new Error('Unexpected call to BaseResource._fetch');
beforeAll(() => {
const signInCreatedJSON = {

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

with new tests and mocks, this was source of failing tests. So I just added moved the into the beforeAll function so we can have more control over order and scope

@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

since there is no change (even backwards compatible) to the sdk api for users, I think we have a patch here -- open to make it a minor as well

@guilherme6191guilherme6191 changed the title feat(i18n): at sign-in, detect locale from browser and send it to FAPI if existsfeat(i18n): At sign-in, detect locale from browser and send it to FAPI if existsOct 16, 2025
@guilherme6191guilherme6191 changed the title feat(i18n): At sign-in, detect locale from browser and send it to FAPI if existsfeat(i18n): Detect locale from browser and send it to FAPI if exists during sign-inOct 16, 2025
@guilherme6191

Copy link
Copy Markdown
ContributorAuthor

Note: I've labeled to do not merge for now as we need FAPI changes released - integration tests should fail because of that too.

return this._basePost({
path: this.pathRoot,
body: params,
body: { ...params, ...(locale ? { locale } : {}) },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe this order should be reversed, as we want to prefer the provided locale from params over the auto-detected one.

@guilherme6191guilherme6191Oct 16, 2025

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

@dstaley, good call. I'm updating the code as it's applicable in case we expose locale as a param as well, which is not the case now.

For now we're not exposing the locale to the sign-in API. We initially think that could add complexity for users and we'll revisit the DX if we expose it. It's available in sign-up as that's more appropriate there. Let me know if that makes sense.

FYI the functionality is going to be behind a FF too.

Comment thread.changeset/quick-kings-rescue.md Outdated
'@clerk/clerk-js': patch
---

Add browser locale to sign-in flow

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Add browser locale to sign-in flow
Add support for automatically sending the browser locale during the sign-in flow

@guilherme6191guilherme6191 changed the title feat(i18n): Detect locale from browser and send it to FAPI if exists during sign-infeat(clerk-js, i18n): Detect locale from browser and send it to FAPI if exists during sign-inOct 16, 2025
@guilherme6191
guilherme6191force-pushed the guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib branch from 7e714c7 to f500017CompareOctober 17, 2025 14:01

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

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 (1)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)

63-93: Consider adding cleanup for consistency.

The centralized mock setup in beforeAll is a good refactor. However, for consistency with the signIn.create suite and to prevent potential cross-suite pollution, consider adding an afterAll or afterEach to clear mocks after the SignInFuture tests complete.

 beforeAll(() => {
...
});
++ afterAll(() => {+ vi.clearAllMocks();+ });
it('should select correct first factor by email address', async () => {
📜 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 7e714c7 and f500017.

📒 Files selected for processing (4)
  • .changeset/quick-kings-rescue.md (1 hunks)
  • packages/clerk-js/src/core/resources/SignIn.ts (4 hunks)
  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1 hunks)
  • packages/clerk-js/vitest.setup.mts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • .changeset/quick-kings-rescue.md
  • packages/clerk-js/vitest.setup.mts
  • packages/clerk-js/src/core/resources/SignIn.ts
🧰 Additional context used
📓 Path-based instructions (9)
**/*.{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/core/resources/__tests__/SignIn.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/core/resources/__tests__/SignIn.test.ts
packages/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
**/__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/core/resources/__tests__/SignIn.test.ts
🧬 Code graph analysis (1)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)
packages/clerk-js/src/core/resources/SignIn.ts (1)
  • SignIn (99-556)
⏰ 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). (27)
  • GitHub Check: Integration Tests (billing, chrome)
  • GitHub Check: Integration Tests (machine, chrome)
  • GitHub Check: Integration Tests (custom, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 14)
  • GitHub Check: Integration Tests (handshake, chrome)
  • GitHub Check: Integration Tests (nuxt, chrome)
  • GitHub Check: Integration Tests (vue, chrome)
  • GitHub Check: Integration Tests (react-router, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 15)
  • GitHub Check: Integration Tests (sessions, chrome)
  • GitHub Check: Integration Tests (express, chrome)
  • GitHub Check: Integration Tests (astro, chrome)
  • GitHub Check: Integration Tests (sessions:staging, chrome)
  • GitHub Check: Integration Tests (tanstack-react-start, chrome)
  • GitHub Check: Integration Tests (localhost, chrome)
  • GitHub Check: Integration Tests (expo-web, chrome)
  • GitHub Check: Integration Tests (ap-flows, chrome)
  • GitHub Check: Integration Tests (handshake:staging, chrome)
  • GitHub Check: Integration Tests (quickstart, chrome)
  • GitHub Check: Integration Tests (elements, chrome)
  • GitHub Check: Integration Tests (generic, chrome)
  • GitHub Check: Static analysis
  • GitHub Check: Publish with pkg-pr-new
  • GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
  • GitHub Check: Unit Tests (22, **)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (1)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)

1-1: LGTM! Well-structured test suite for locale behavior.

The new test suite properly validates that:

  • Locale is included in the request body when navigator.language is set (test 1)
  • Locale is excluded when navigator.language is empty (test 2)

The cleanup in afterEach correctly addresses the past review concern about stubbed globals persisting across tests.

Also applies to: 7-59

@guilherme6191guilherme6191 changed the title feat(clerk-js, i18n): Detect locale from browser and send it to FAPI if exists during sign-infeat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n)Oct 17, 2025
Comment threadpackages/clerk-js/src/core/resources/SignIn.ts Outdated
Comment threadpackages/clerk-js/src/core/resources/SignIn.ts Outdated
@guilherme6191
guilherme6191 merged commit 6503405 into mainOct 17, 2025
41 checks passed
@guilherme6191
guilherme6191 deleted the guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib branch October 17, 2025 16:34
NicolasLopes7 pushed a commit that referenced this pull request Oct 23, 2025
Sign up for freeto 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

@guilherme6191@tmilewski@dstaley@clerk-cookie
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

feat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n) - #7011

Merged
guilherme6191 merged 6 commits into
mainfrom
guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib
Oct 17, 2025
Merged

feat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n)#7011
guilherme6191 merged 6 commits into
mainfrom
guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib

Conversation

@guilherme6191

@guilherme6191guilherme6191 commented Oct 16, 2025

Copy link
Copy Markdown
Contributor

Description

This PR adds auto detection of browser locale (navigator.language) and sends that to sign-in flow. This is similar to the behavior implemented for the sign-up (#6915), but does not expose locale in the API to reduce noise/complexity at sign-in for now.

For extra context: this is a change where we'll be storing users preferred language from the browser, and C1s can update via BAPI (later on via dashboard and AIOs) so we can send localized templates. The whole feature is behind a FF and we're rolling out only for Spark (new customer implementing Clerk).

https://linear.app/clerk/issue/USER-3712/detect-and-send-locale-in-sign-ins-js-lib

Note: needs https://github.com/clerk/clerk_go/pull/14182 released

Checklist

Type of change

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

Summary by CodeRabbit

  • New Features

    • Sign-in flow now detects and automatically sends the browser locale to improve localization during authentication.
  • Tests

    • Added tests verifying locale is included when present and omitted when absent.
    • Test setup updated for a predictable navigator.language and centralized mock/cleanup to stabilize sign-in test suites.

@changeset-bot

changeset-botBot commented Oct 16, 2025

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c781372

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

This PR includes changesets to release 3 packages
NameType
@clerk/clerk-jsPatch
@clerk/chrome-extensionPatch
@clerk/clerk-expoPatch

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

@vercel

vercelBot commented Oct 16, 2025

Copy link
Copy Markdown

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

ProjectDeploymentPreviewCommentsUpdated (UTC)
clerk-js-sandboxReadyReadyPreviewCommentOct 17, 2025 4:21pm

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

@coderabbitai

coderabbitaiBot commented Oct 16, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Adds browser locale detection to the @clerk/clerk-js sign-in flow by calling getBrowserLocale() and conditionally including the locale in sign-in request bodies; if no locale is detected, requests omit the locale.

Changes

Cohort / File(s)Summary
Changeset documentation
​.changeset/quick-kings-rescue.md
Patch release entry noting addition of browser locale to sign-in flow.
Sign-in implementation
packages/clerk-js/src/core/resources/SignIn.ts
Computes locale via getBrowserLocale() and conditionally injects it into request bodies for SignIn.create, SignInFuture._create, and SignInFuture.password.
Sign-in tests
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
Adds tests asserting locale is included when navigator.language is set and excluded when empty; centralizes mock setup via beforeAll and resets mocks/unstubs in afterEach.
Test environment setup
packages/clerk-js/vitest.setup.mts
Sets window.navigator.language to an empty string ('') in the Vitest/jsdom setup.

Sequence Diagram(s)

sequenceDiagram
participant User
participant Browser
participant SignIn
participant Server
User->>SignIn: start sign-in (create / password)
SignIn->>Browser: getBrowserLocale()
alt locale detected
Browser-->>SignIn: "en-US" (example)
Note right of SignIn: include `locale` in request body
else locale not detected
Browser-->>SignIn: "" / undefined
Note right of SignIn: omit `locale` from request body
end
SignIn->>Server: POST /sign-in (body with/without locale)
Server-->>SignIn: response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I sniffed the browser breeze and found a clue,
I tucked the locale in the sign-in stew,
If silence whispered, I hopped away light,
The flow went on, tidy and right,
A tiny hop toward doing it true.

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title Check✅ PassedThe pull request title "feat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n)" is highly specific and accurately summarizes the main changes in the PR. It clearly communicates that the feature detects browser locale and sends it during sign-in, which aligns with all modifications across SignIn.ts, tests, and test setup. The title is concise, follows conventional commit formatting, and avoids vague terminology, making it immediately clear to reviewers what the core change accomplishes.
Linked Issues Check✅ PassedThe code changes fully satisfy the three primary objectives from USER-3712: locale detection from the browser is implemented via getBrowserLocale() [USER-3712], sending to the FAPI sign-in flow is accomplished by merging locale into the request body in SignIn.ts [USER-3712], and conditional sending without error handling is correctly implemented by only including locale when it is truthy [USER-3712]. The test suite validates both conditions—inclusion when navigator.language is set and exclusion when empty—confirming the implementation matches the requirements.
Out of Scope Changes Check✅ PassedAll changes in the pull request are directly related to the USER-3712 objective of detecting and sending browser locale during sign-in. The modifications to SignIn.ts implement the core feature, the test additions in SignIn.test.ts validate the locale detection and transmission, the changeset documents the new capability, and the vitest setup change provides test infrastructure support by mocking navigator.language. No unrelated refactoring, cleanup, or out-of-scope modifications are present.
Docstring Coverage✅ PassedNo 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 guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib

📜 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 f500017 and c781372.

📒 Files selected for processing (1)
  • packages/clerk-js/src/core/resources/SignIn.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/clerk-js/src/core/resources/SignIn.ts
⏰ 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

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

@pkg-pr-new

pkg-pr-newBot commented Oct 16, 2025

Copy link
Copy Markdown

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

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

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

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

@clerk/types

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

@clerk/upgrade

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

@clerk/vue

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

commit: c781372

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

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 160dc93 and 231a103.

📒 Files selected for processing (4)
  • .changeset/quick-kings-rescue.md (1 hunks)
  • packages/clerk-js/src/core/resources/SignIn.ts (4 hunks)
  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1 hunks)
  • packages/clerk-js/vitest.setup.mts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (10)
.changeset/**

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

Automated releases must use Changesets.

Files:

  • .changeset/quick-kings-rescue.md
**/*.{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/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.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/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
packages/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
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/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
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/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
**/__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/core/resources/__tests__/SignIn.test.ts
🧬 Code graph analysis (2)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)
packages/clerk-js/src/core/resources/SignIn.ts (1)
  • SignIn (99-556)
packages/clerk-js/src/core/resources/SignIn.ts (2)
packages/clerk-js/src/core/resources/SignUp.ts (1)
  • locale (650-652)
packages/clerk-js/src/utils/locale.ts (1)
  • getBrowserLocale (11-28)
⏰ 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). (2)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan


throw new Error('Unexpected call to BaseResource._fetch');
beforeAll(() => {
const signInCreatedJSON = {

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

with new tests and mocks, this was source of failing tests. So I just added moved the into the beforeAll function so we can have more control over order and scope

@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

since there is no change (even backwards compatible) to the sdk api for users, I think we have a patch here -- open to make it a minor as well

@guilherme6191guilherme6191 changed the title feat(i18n): at sign-in, detect locale from browser and send it to FAPI if existsfeat(i18n): At sign-in, detect locale from browser and send it to FAPI if existsOct 16, 2025
@guilherme6191guilherme6191 changed the title feat(i18n): At sign-in, detect locale from browser and send it to FAPI if existsfeat(i18n): Detect locale from browser and send it to FAPI if exists during sign-inOct 16, 2025
@guilherme6191

Copy link
Copy Markdown
ContributorAuthor

Note: I've labeled to do not merge for now as we need FAPI changes released - integration tests should fail because of that too.

return this._basePost({
path: this.pathRoot,
body: params,
body: { ...params, ...(locale ? { locale } : {}) },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe this order should be reversed, as we want to prefer the provided locale from params over the auto-detected one.

@guilherme6191guilherme6191Oct 16, 2025

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

@dstaley, good call. I'm updating the code as it's applicable in case we expose locale as a param as well, which is not the case now.

For now we're not exposing the locale to the sign-in API. We initially think that could add complexity for users and we'll revisit the DX if we expose it. It's available in sign-up as that's more appropriate there. Let me know if that makes sense.

FYI the functionality is going to be behind a FF too.

Comment thread.changeset/quick-kings-rescue.md Outdated
'@clerk/clerk-js': patch
---

Add browser locale to sign-in flow

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Add browser locale to sign-in flow
Add support for automatically sending the browser locale during the sign-in flow

@guilherme6191guilherme6191 changed the title feat(i18n): Detect locale from browser and send it to FAPI if exists during sign-infeat(clerk-js, i18n): Detect locale from browser and send it to FAPI if exists during sign-inOct 16, 2025
@guilherme6191
guilherme6191force-pushed the guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib branch from 7e714c7 to f500017CompareOctober 17, 2025 14:01

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

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 (1)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)

63-93: Consider adding cleanup for consistency.

The centralized mock setup in beforeAll is a good refactor. However, for consistency with the signIn.create suite and to prevent potential cross-suite pollution, consider adding an afterAll or afterEach to clear mocks after the SignInFuture tests complete.

 beforeAll(() => {
...
});
++ afterAll(() => {+ vi.clearAllMocks();+ });
it('should select correct first factor by email address', async () => {
📜 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 7e714c7 and f500017.

📒 Files selected for processing (4)
  • .changeset/quick-kings-rescue.md (1 hunks)
  • packages/clerk-js/src/core/resources/SignIn.ts (4 hunks)
  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1 hunks)
  • packages/clerk-js/vitest.setup.mts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • .changeset/quick-kings-rescue.md
  • packages/clerk-js/vitest.setup.mts
  • packages/clerk-js/src/core/resources/SignIn.ts
🧰 Additional context used
📓 Path-based instructions (9)
**/*.{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/core/resources/__tests__/SignIn.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/core/resources/__tests__/SignIn.test.ts
packages/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
**/__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/core/resources/__tests__/SignIn.test.ts
🧬 Code graph analysis (1)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)
packages/clerk-js/src/core/resources/SignIn.ts (1)
  • SignIn (99-556)
⏰ 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). (27)
  • GitHub Check: Integration Tests (billing, chrome)
  • GitHub Check: Integration Tests (machine, chrome)
  • GitHub Check: Integration Tests (custom, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 14)
  • GitHub Check: Integration Tests (handshake, chrome)
  • GitHub Check: Integration Tests (nuxt, chrome)
  • GitHub Check: Integration Tests (vue, chrome)
  • GitHub Check: Integration Tests (react-router, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 15)
  • GitHub Check: Integration Tests (sessions, chrome)
  • GitHub Check: Integration Tests (express, chrome)
  • GitHub Check: Integration Tests (astro, chrome)
  • GitHub Check: Integration Tests (sessions:staging, chrome)
  • GitHub Check: Integration Tests (tanstack-react-start, chrome)
  • GitHub Check: Integration Tests (localhost, chrome)
  • GitHub Check: Integration Tests (expo-web, chrome)
  • GitHub Check: Integration Tests (ap-flows, chrome)
  • GitHub Check: Integration Tests (handshake:staging, chrome)
  • GitHub Check: Integration Tests (quickstart, chrome)
  • GitHub Check: Integration Tests (elements, chrome)
  • GitHub Check: Integration Tests (generic, chrome)
  • GitHub Check: Static analysis
  • GitHub Check: Publish with pkg-pr-new
  • GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
  • GitHub Check: Unit Tests (22, **)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (1)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)

1-1: LGTM! Well-structured test suite for locale behavior.

The new test suite properly validates that:

  • Locale is included in the request body when navigator.language is set (test 1)
  • Locale is excluded when navigator.language is empty (test 2)

The cleanup in afterEach correctly addresses the past review concern about stubbed globals persisting across tests.

Also applies to: 7-59

@guilherme6191guilherme6191 changed the title feat(clerk-js, i18n): Detect locale from browser and send it to FAPI if exists during sign-infeat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n)Oct 17, 2025
Comment threadpackages/clerk-js/src/core/resources/SignIn.ts Outdated
Comment threadpackages/clerk-js/src/core/resources/SignIn.ts Outdated
@guilherme6191
guilherme6191 merged commit 6503405 into mainOct 17, 2025
41 checks passed
@guilherme6191
guilherme6191 deleted the guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib branch October 17, 2025 16:34
NicolasLopes7 pushed a commit that referenced this pull request Oct 23, 2025
Sign up for freeto 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

@guilherme6191@tmilewski@dstaley@clerk-cookie
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

feat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n) - #7011

Merged
guilherme6191 merged 6 commits into
mainfrom
guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib
Oct 17, 2025
Merged

feat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n)#7011
guilherme6191 merged 6 commits into
mainfrom
guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib

Conversation

@guilherme6191

@guilherme6191guilherme6191 commented Oct 16, 2025

Copy link
Copy Markdown
Contributor

Description

This PR adds auto detection of browser locale (navigator.language) and sends that to sign-in flow. This is similar to the behavior implemented for the sign-up (#6915), but does not expose locale in the API to reduce noise/complexity at sign-in for now.

For extra context: this is a change where we'll be storing users preferred language from the browser, and C1s can update via BAPI (later on via dashboard and AIOs) so we can send localized templates. The whole feature is behind a FF and we're rolling out only for Spark (new customer implementing Clerk).

https://linear.app/clerk/issue/USER-3712/detect-and-send-locale-in-sign-ins-js-lib

Note: needs https://github.com/clerk/clerk_go/pull/14182 released

Checklist

Type of change

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

Summary by CodeRabbit

  • New Features

    • Sign-in flow now detects and automatically sends the browser locale to improve localization during authentication.
  • Tests

    • Added tests verifying locale is included when present and omitted when absent.
    • Test setup updated for a predictable navigator.language and centralized mock/cleanup to stabilize sign-in test suites.

@changeset-bot

changeset-botBot commented Oct 16, 2025

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c781372

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

This PR includes changesets to release 3 packages
NameType
@clerk/clerk-jsPatch
@clerk/chrome-extensionPatch
@clerk/clerk-expoPatch

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

@vercel

vercelBot commented Oct 16, 2025

Copy link
Copy Markdown

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

ProjectDeploymentPreviewCommentsUpdated (UTC)
clerk-js-sandboxReadyReadyPreviewCommentOct 17, 2025 4:21pm

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

@coderabbitai

coderabbitaiBot commented Oct 16, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Adds browser locale detection to the @clerk/clerk-js sign-in flow by calling getBrowserLocale() and conditionally including the locale in sign-in request bodies; if no locale is detected, requests omit the locale.

Changes

Cohort / File(s)Summary
Changeset documentation
​.changeset/quick-kings-rescue.md
Patch release entry noting addition of browser locale to sign-in flow.
Sign-in implementation
packages/clerk-js/src/core/resources/SignIn.ts
Computes locale via getBrowserLocale() and conditionally injects it into request bodies for SignIn.create, SignInFuture._create, and SignInFuture.password.
Sign-in tests
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
Adds tests asserting locale is included when navigator.language is set and excluded when empty; centralizes mock setup via beforeAll and resets mocks/unstubs in afterEach.
Test environment setup
packages/clerk-js/vitest.setup.mts
Sets window.navigator.language to an empty string ('') in the Vitest/jsdom setup.

Sequence Diagram(s)

sequenceDiagram
participant User
participant Browser
participant SignIn
participant Server
User->>SignIn: start sign-in (create / password)
SignIn->>Browser: getBrowserLocale()
alt locale detected
Browser-->>SignIn: "en-US" (example)
Note right of SignIn: include `locale` in request body
else locale not detected
Browser-->>SignIn: "" / undefined
Note right of SignIn: omit `locale` from request body
end
SignIn->>Server: POST /sign-in (body with/without locale)
Server-->>SignIn: response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I sniffed the browser breeze and found a clue,
I tucked the locale in the sign-in stew,
If silence whispered, I hopped away light,
The flow went on, tidy and right,
A tiny hop toward doing it true.

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title Check✅ PassedThe pull request title "feat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n)" is highly specific and accurately summarizes the main changes in the PR. It clearly communicates that the feature detects browser locale and sends it during sign-in, which aligns with all modifications across SignIn.ts, tests, and test setup. The title is concise, follows conventional commit formatting, and avoids vague terminology, making it immediately clear to reviewers what the core change accomplishes.
Linked Issues Check✅ PassedThe code changes fully satisfy the three primary objectives from USER-3712: locale detection from the browser is implemented via getBrowserLocale() [USER-3712], sending to the FAPI sign-in flow is accomplished by merging locale into the request body in SignIn.ts [USER-3712], and conditional sending without error handling is correctly implemented by only including locale when it is truthy [USER-3712]. The test suite validates both conditions—inclusion when navigator.language is set and exclusion when empty—confirming the implementation matches the requirements.
Out of Scope Changes Check✅ PassedAll changes in the pull request are directly related to the USER-3712 objective of detecting and sending browser locale during sign-in. The modifications to SignIn.ts implement the core feature, the test additions in SignIn.test.ts validate the locale detection and transmission, the changeset documents the new capability, and the vitest setup change provides test infrastructure support by mocking navigator.language. No unrelated refactoring, cleanup, or out-of-scope modifications are present.
Docstring Coverage✅ PassedNo 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 guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib

📜 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 f500017 and c781372.

📒 Files selected for processing (1)
  • packages/clerk-js/src/core/resources/SignIn.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/clerk-js/src/core/resources/SignIn.ts
⏰ 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

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

@pkg-pr-new

pkg-pr-newBot commented Oct 16, 2025

Copy link
Copy Markdown

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

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

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

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

@clerk/types

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

@clerk/upgrade

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

@clerk/vue

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

commit: c781372

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

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 160dc93 and 231a103.

📒 Files selected for processing (4)
  • .changeset/quick-kings-rescue.md (1 hunks)
  • packages/clerk-js/src/core/resources/SignIn.ts (4 hunks)
  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1 hunks)
  • packages/clerk-js/vitest.setup.mts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (10)
.changeset/**

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

Automated releases must use Changesets.

Files:

  • .changeset/quick-kings-rescue.md
**/*.{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/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.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/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
packages/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
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/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
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/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
**/__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/core/resources/__tests__/SignIn.test.ts
🧬 Code graph analysis (2)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)
packages/clerk-js/src/core/resources/SignIn.ts (1)
  • SignIn (99-556)
packages/clerk-js/src/core/resources/SignIn.ts (2)
packages/clerk-js/src/core/resources/SignUp.ts (1)
  • locale (650-652)
packages/clerk-js/src/utils/locale.ts (1)
  • getBrowserLocale (11-28)
⏰ 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). (2)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan


throw new Error('Unexpected call to BaseResource._fetch');
beforeAll(() => {
const signInCreatedJSON = {

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

with new tests and mocks, this was source of failing tests. So I just added moved the into the beforeAll function so we can have more control over order and scope

@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

since there is no change (even backwards compatible) to the sdk api for users, I think we have a patch here -- open to make it a minor as well

@guilherme6191guilherme6191 changed the title feat(i18n): at sign-in, detect locale from browser and send it to FAPI if existsfeat(i18n): At sign-in, detect locale from browser and send it to FAPI if existsOct 16, 2025
@guilherme6191guilherme6191 changed the title feat(i18n): At sign-in, detect locale from browser and send it to FAPI if existsfeat(i18n): Detect locale from browser and send it to FAPI if exists during sign-inOct 16, 2025
@guilherme6191

Copy link
Copy Markdown
ContributorAuthor

Note: I've labeled to do not merge for now as we need FAPI changes released - integration tests should fail because of that too.

return this._basePost({
path: this.pathRoot,
body: params,
body: { ...params, ...(locale ? { locale } : {}) },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe this order should be reversed, as we want to prefer the provided locale from params over the auto-detected one.

@guilherme6191guilherme6191Oct 16, 2025

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

@dstaley, good call. I'm updating the code as it's applicable in case we expose locale as a param as well, which is not the case now.

For now we're not exposing the locale to the sign-in API. We initially think that could add complexity for users and we'll revisit the DX if we expose it. It's available in sign-up as that's more appropriate there. Let me know if that makes sense.

FYI the functionality is going to be behind a FF too.

Comment thread.changeset/quick-kings-rescue.md Outdated
'@clerk/clerk-js': patch
---

Add browser locale to sign-in flow

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Add browser locale to sign-in flow
Add support for automatically sending the browser locale during the sign-in flow

@guilherme6191guilherme6191 changed the title feat(i18n): Detect locale from browser and send it to FAPI if exists during sign-infeat(clerk-js, i18n): Detect locale from browser and send it to FAPI if exists during sign-inOct 16, 2025
@guilherme6191
guilherme6191force-pushed the guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib branch from 7e714c7 to f500017CompareOctober 17, 2025 14:01

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

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 (1)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)

63-93: Consider adding cleanup for consistency.

The centralized mock setup in beforeAll is a good refactor. However, for consistency with the signIn.create suite and to prevent potential cross-suite pollution, consider adding an afterAll or afterEach to clear mocks after the SignInFuture tests complete.

 beforeAll(() => {
...
});
++ afterAll(() => {+ vi.clearAllMocks();+ });
it('should select correct first factor by email address', async () => {
📜 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 7e714c7 and f500017.

📒 Files selected for processing (4)
  • .changeset/quick-kings-rescue.md (1 hunks)
  • packages/clerk-js/src/core/resources/SignIn.ts (4 hunks)
  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1 hunks)
  • packages/clerk-js/vitest.setup.mts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • .changeset/quick-kings-rescue.md
  • packages/clerk-js/vitest.setup.mts
  • packages/clerk-js/src/core/resources/SignIn.ts
🧰 Additional context used
📓 Path-based instructions (9)
**/*.{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/core/resources/__tests__/SignIn.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/core/resources/__tests__/SignIn.test.ts
packages/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
**/__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/core/resources/__tests__/SignIn.test.ts
🧬 Code graph analysis (1)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)
packages/clerk-js/src/core/resources/SignIn.ts (1)
  • SignIn (99-556)
⏰ 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). (27)
  • GitHub Check: Integration Tests (billing, chrome)
  • GitHub Check: Integration Tests (machine, chrome)
  • GitHub Check: Integration Tests (custom, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 14)
  • GitHub Check: Integration Tests (handshake, chrome)
  • GitHub Check: Integration Tests (nuxt, chrome)
  • GitHub Check: Integration Tests (vue, chrome)
  • GitHub Check: Integration Tests (react-router, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 15)
  • GitHub Check: Integration Tests (sessions, chrome)
  • GitHub Check: Integration Tests (express, chrome)
  • GitHub Check: Integration Tests (astro, chrome)
  • GitHub Check: Integration Tests (sessions:staging, chrome)
  • GitHub Check: Integration Tests (tanstack-react-start, chrome)
  • GitHub Check: Integration Tests (localhost, chrome)
  • GitHub Check: Integration Tests (expo-web, chrome)
  • GitHub Check: Integration Tests (ap-flows, chrome)
  • GitHub Check: Integration Tests (handshake:staging, chrome)
  • GitHub Check: Integration Tests (quickstart, chrome)
  • GitHub Check: Integration Tests (elements, chrome)
  • GitHub Check: Integration Tests (generic, chrome)
  • GitHub Check: Static analysis
  • GitHub Check: Publish with pkg-pr-new
  • GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
  • GitHub Check: Unit Tests (22, **)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (1)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)

1-1: LGTM! Well-structured test suite for locale behavior.

The new test suite properly validates that:

  • Locale is included in the request body when navigator.language is set (test 1)
  • Locale is excluded when navigator.language is empty (test 2)

The cleanup in afterEach correctly addresses the past review concern about stubbed globals persisting across tests.

Also applies to: 7-59

@guilherme6191guilherme6191 changed the title feat(clerk-js, i18n): Detect locale from browser and send it to FAPI if exists during sign-infeat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n)Oct 17, 2025
Comment threadpackages/clerk-js/src/core/resources/SignIn.ts Outdated
Comment threadpackages/clerk-js/src/core/resources/SignIn.ts Outdated
@guilherme6191
guilherme6191 merged commit 6503405 into mainOct 17, 2025
41 checks passed
@guilherme6191
guilherme6191 deleted the guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib branch October 17, 2025 16:34
NicolasLopes7 pushed a commit that referenced this pull request Oct 23, 2025
Sign up for freeto 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

@guilherme6191@tmilewski@dstaley@clerk-cookie
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

feat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n) - #7011

Merged
guilherme6191 merged 6 commits into
mainfrom
guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib
Oct 17, 2025
Merged

feat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n)#7011
guilherme6191 merged 6 commits into
mainfrom
guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib

Conversation

@guilherme6191

@guilherme6191guilherme6191 commented Oct 16, 2025

Copy link
Copy Markdown
Contributor

Description

This PR adds auto detection of browser locale (navigator.language) and sends that to sign-in flow. This is similar to the behavior implemented for the sign-up (#6915), but does not expose locale in the API to reduce noise/complexity at sign-in for now.

For extra context: this is a change where we'll be storing users preferred language from the browser, and C1s can update via BAPI (later on via dashboard and AIOs) so we can send localized templates. The whole feature is behind a FF and we're rolling out only for Spark (new customer implementing Clerk).

https://linear.app/clerk/issue/USER-3712/detect-and-send-locale-in-sign-ins-js-lib

Note: needs https://github.com/clerk/clerk_go/pull/14182 released

Checklist

Type of change

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

Summary by CodeRabbit

  • New Features

    • Sign-in flow now detects and automatically sends the browser locale to improve localization during authentication.
  • Tests

    • Added tests verifying locale is included when present and omitted when absent.
    • Test setup updated for a predictable navigator.language and centralized mock/cleanup to stabilize sign-in test suites.

@changeset-bot

changeset-botBot commented Oct 16, 2025

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c781372

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

This PR includes changesets to release 3 packages
NameType
@clerk/clerk-jsPatch
@clerk/chrome-extensionPatch
@clerk/clerk-expoPatch

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

@vercel

vercelBot commented Oct 16, 2025

Copy link
Copy Markdown

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

ProjectDeploymentPreviewCommentsUpdated (UTC)
clerk-js-sandboxReadyReadyPreviewCommentOct 17, 2025 4:21pm

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

@coderabbitai

coderabbitaiBot commented Oct 16, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Adds browser locale detection to the @clerk/clerk-js sign-in flow by calling getBrowserLocale() and conditionally including the locale in sign-in request bodies; if no locale is detected, requests omit the locale.

Changes

Cohort / File(s)Summary
Changeset documentation
​.changeset/quick-kings-rescue.md
Patch release entry noting addition of browser locale to sign-in flow.
Sign-in implementation
packages/clerk-js/src/core/resources/SignIn.ts
Computes locale via getBrowserLocale() and conditionally injects it into request bodies for SignIn.create, SignInFuture._create, and SignInFuture.password.
Sign-in tests
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
Adds tests asserting locale is included when navigator.language is set and excluded when empty; centralizes mock setup via beforeAll and resets mocks/unstubs in afterEach.
Test environment setup
packages/clerk-js/vitest.setup.mts
Sets window.navigator.language to an empty string ('') in the Vitest/jsdom setup.

Sequence Diagram(s)

sequenceDiagram
participant User
participant Browser
participant SignIn
participant Server
User->>SignIn: start sign-in (create / password)
SignIn->>Browser: getBrowserLocale()
alt locale detected
Browser-->>SignIn: "en-US" (example)
Note right of SignIn: include `locale` in request body
else locale not detected
Browser-->>SignIn: "" / undefined
Note right of SignIn: omit `locale` from request body
end
SignIn->>Server: POST /sign-in (body with/without locale)
Server-->>SignIn: response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I sniffed the browser breeze and found a clue,
I tucked the locale in the sign-in stew,
If silence whispered, I hopped away light,
The flow went on, tidy and right,
A tiny hop toward doing it true.

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title Check✅ PassedThe pull request title "feat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n)" is highly specific and accurately summarizes the main changes in the PR. It clearly communicates that the feature detects browser locale and sends it during sign-in, which aligns with all modifications across SignIn.ts, tests, and test setup. The title is concise, follows conventional commit formatting, and avoids vague terminology, making it immediately clear to reviewers what the core change accomplishes.
Linked Issues Check✅ PassedThe code changes fully satisfy the three primary objectives from USER-3712: locale detection from the browser is implemented via getBrowserLocale() [USER-3712], sending to the FAPI sign-in flow is accomplished by merging locale into the request body in SignIn.ts [USER-3712], and conditional sending without error handling is correctly implemented by only including locale when it is truthy [USER-3712]. The test suite validates both conditions—inclusion when navigator.language is set and exclusion when empty—confirming the implementation matches the requirements.
Out of Scope Changes Check✅ PassedAll changes in the pull request are directly related to the USER-3712 objective of detecting and sending browser locale during sign-in. The modifications to SignIn.ts implement the core feature, the test additions in SignIn.test.ts validate the locale detection and transmission, the changeset documents the new capability, and the vitest setup change provides test infrastructure support by mocking navigator.language. No unrelated refactoring, cleanup, or out-of-scope modifications are present.
Docstring Coverage✅ PassedNo 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 guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib

📜 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 f500017 and c781372.

📒 Files selected for processing (1)
  • packages/clerk-js/src/core/resources/SignIn.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/clerk-js/src/core/resources/SignIn.ts
⏰ 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

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

@pkg-pr-new

pkg-pr-newBot commented Oct 16, 2025

Copy link
Copy Markdown

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

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

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

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

@clerk/types

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

@clerk/upgrade

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

@clerk/vue

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

commit: c781372

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

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 160dc93 and 231a103.

📒 Files selected for processing (4)
  • .changeset/quick-kings-rescue.md (1 hunks)
  • packages/clerk-js/src/core/resources/SignIn.ts (4 hunks)
  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1 hunks)
  • packages/clerk-js/vitest.setup.mts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (10)
.changeset/**

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

Automated releases must use Changesets.

Files:

  • .changeset/quick-kings-rescue.md
**/*.{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/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.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/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
packages/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
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/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
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/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
**/__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/core/resources/__tests__/SignIn.test.ts
🧬 Code graph analysis (2)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)
packages/clerk-js/src/core/resources/SignIn.ts (1)
  • SignIn (99-556)
packages/clerk-js/src/core/resources/SignIn.ts (2)
packages/clerk-js/src/core/resources/SignUp.ts (1)
  • locale (650-652)
packages/clerk-js/src/utils/locale.ts (1)
  • getBrowserLocale (11-28)
⏰ 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). (2)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan


throw new Error('Unexpected call to BaseResource._fetch');
beforeAll(() => {
const signInCreatedJSON = {

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

with new tests and mocks, this was source of failing tests. So I just added moved the into the beforeAll function so we can have more control over order and scope

@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

since there is no change (even backwards compatible) to the sdk api for users, I think we have a patch here -- open to make it a minor as well

@guilherme6191guilherme6191 changed the title feat(i18n): at sign-in, detect locale from browser and send it to FAPI if existsfeat(i18n): At sign-in, detect locale from browser and send it to FAPI if existsOct 16, 2025
@guilherme6191guilherme6191 changed the title feat(i18n): At sign-in, detect locale from browser and send it to FAPI if existsfeat(i18n): Detect locale from browser and send it to FAPI if exists during sign-inOct 16, 2025
@guilherme6191

Copy link
Copy Markdown
ContributorAuthor

Note: I've labeled to do not merge for now as we need FAPI changes released - integration tests should fail because of that too.

return this._basePost({
path: this.pathRoot,
body: params,
body: { ...params, ...(locale ? { locale } : {}) },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe this order should be reversed, as we want to prefer the provided locale from params over the auto-detected one.

@guilherme6191guilherme6191Oct 16, 2025

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

@dstaley, good call. I'm updating the code as it's applicable in case we expose locale as a param as well, which is not the case now.

For now we're not exposing the locale to the sign-in API. We initially think that could add complexity for users and we'll revisit the DX if we expose it. It's available in sign-up as that's more appropriate there. Let me know if that makes sense.

FYI the functionality is going to be behind a FF too.

Comment thread.changeset/quick-kings-rescue.md Outdated
'@clerk/clerk-js': patch
---

Add browser locale to sign-in flow

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Add browser locale to sign-in flow
Add support for automatically sending the browser locale during the sign-in flow

@guilherme6191guilherme6191 changed the title feat(i18n): Detect locale from browser and send it to FAPI if exists during sign-infeat(clerk-js, i18n): Detect locale from browser and send it to FAPI if exists during sign-inOct 16, 2025
@guilherme6191
guilherme6191force-pushed the guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib branch from 7e714c7 to f500017CompareOctober 17, 2025 14:01

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

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 (1)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)

63-93: Consider adding cleanup for consistency.

The centralized mock setup in beforeAll is a good refactor. However, for consistency with the signIn.create suite and to prevent potential cross-suite pollution, consider adding an afterAll or afterEach to clear mocks after the SignInFuture tests complete.

 beforeAll(() => {
...
});
++ afterAll(() => {+ vi.clearAllMocks();+ });
it('should select correct first factor by email address', async () => {
📜 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 7e714c7 and f500017.

📒 Files selected for processing (4)
  • .changeset/quick-kings-rescue.md (1 hunks)
  • packages/clerk-js/src/core/resources/SignIn.ts (4 hunks)
  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1 hunks)
  • packages/clerk-js/vitest.setup.mts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • .changeset/quick-kings-rescue.md
  • packages/clerk-js/vitest.setup.mts
  • packages/clerk-js/src/core/resources/SignIn.ts
🧰 Additional context used
📓 Path-based instructions (9)
**/*.{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/core/resources/__tests__/SignIn.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/core/resources/__tests__/SignIn.test.ts
packages/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
**/__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/core/resources/__tests__/SignIn.test.ts
🧬 Code graph analysis (1)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)
packages/clerk-js/src/core/resources/SignIn.ts (1)
  • SignIn (99-556)
⏰ 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). (27)
  • GitHub Check: Integration Tests (billing, chrome)
  • GitHub Check: Integration Tests (machine, chrome)
  • GitHub Check: Integration Tests (custom, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 14)
  • GitHub Check: Integration Tests (handshake, chrome)
  • GitHub Check: Integration Tests (nuxt, chrome)
  • GitHub Check: Integration Tests (vue, chrome)
  • GitHub Check: Integration Tests (react-router, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 15)
  • GitHub Check: Integration Tests (sessions, chrome)
  • GitHub Check: Integration Tests (express, chrome)
  • GitHub Check: Integration Tests (astro, chrome)
  • GitHub Check: Integration Tests (sessions:staging, chrome)
  • GitHub Check: Integration Tests (tanstack-react-start, chrome)
  • GitHub Check: Integration Tests (localhost, chrome)
  • GitHub Check: Integration Tests (expo-web, chrome)
  • GitHub Check: Integration Tests (ap-flows, chrome)
  • GitHub Check: Integration Tests (handshake:staging, chrome)
  • GitHub Check: Integration Tests (quickstart, chrome)
  • GitHub Check: Integration Tests (elements, chrome)
  • GitHub Check: Integration Tests (generic, chrome)
  • GitHub Check: Static analysis
  • GitHub Check: Publish with pkg-pr-new
  • GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
  • GitHub Check: Unit Tests (22, **)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (1)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)

1-1: LGTM! Well-structured test suite for locale behavior.

The new test suite properly validates that:

  • Locale is included in the request body when navigator.language is set (test 1)
  • Locale is excluded when navigator.language is empty (test 2)

The cleanup in afterEach correctly addresses the past review concern about stubbed globals persisting across tests.

Also applies to: 7-59

@guilherme6191guilherme6191 changed the title feat(clerk-js, i18n): Detect locale from browser and send it to FAPI if exists during sign-infeat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n)Oct 17, 2025
Comment threadpackages/clerk-js/src/core/resources/SignIn.ts Outdated
Comment threadpackages/clerk-js/src/core/resources/SignIn.ts Outdated
@guilherme6191
guilherme6191 merged commit 6503405 into mainOct 17, 2025
41 checks passed
@guilherme6191
guilherme6191 deleted the guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib branch October 17, 2025 16:34
NicolasLopes7 pushed a commit that referenced this pull request Oct 23, 2025
Sign up for freeto 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

@guilherme6191@tmilewski@dstaley@clerk-cookie
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

feat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n) - #7011

Merged
guilherme6191 merged 6 commits into
mainfrom
guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib
Oct 17, 2025
Merged

feat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n)#7011
guilherme6191 merged 6 commits into
mainfrom
guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib

Conversation

@guilherme6191

@guilherme6191guilherme6191 commented Oct 16, 2025

Copy link
Copy Markdown
Contributor

Description

This PR adds auto detection of browser locale (navigator.language) and sends that to sign-in flow. This is similar to the behavior implemented for the sign-up (#6915), but does not expose locale in the API to reduce noise/complexity at sign-in for now.

For extra context: this is a change where we'll be storing users preferred language from the browser, and C1s can update via BAPI (later on via dashboard and AIOs) so we can send localized templates. The whole feature is behind a FF and we're rolling out only for Spark (new customer implementing Clerk).

https://linear.app/clerk/issue/USER-3712/detect-and-send-locale-in-sign-ins-js-lib

Note: needs https://github.com/clerk/clerk_go/pull/14182 released

Checklist

Type of change

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

Summary by CodeRabbit

  • New Features

    • Sign-in flow now detects and automatically sends the browser locale to improve localization during authentication.
  • Tests

    • Added tests verifying locale is included when present and omitted when absent.
    • Test setup updated for a predictable navigator.language and centralized mock/cleanup to stabilize sign-in test suites.

@changeset-bot

changeset-botBot commented Oct 16, 2025

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c781372

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

This PR includes changesets to release 3 packages
NameType
@clerk/clerk-jsPatch
@clerk/chrome-extensionPatch
@clerk/clerk-expoPatch

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

@vercel

vercelBot commented Oct 16, 2025

Copy link
Copy Markdown

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

ProjectDeploymentPreviewCommentsUpdated (UTC)
clerk-js-sandboxReadyReadyPreviewCommentOct 17, 2025 4:21pm

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

@coderabbitai

coderabbitaiBot commented Oct 16, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Adds browser locale detection to the @clerk/clerk-js sign-in flow by calling getBrowserLocale() and conditionally including the locale in sign-in request bodies; if no locale is detected, requests omit the locale.

Changes

Cohort / File(s)Summary
Changeset documentation
​.changeset/quick-kings-rescue.md
Patch release entry noting addition of browser locale to sign-in flow.
Sign-in implementation
packages/clerk-js/src/core/resources/SignIn.ts
Computes locale via getBrowserLocale() and conditionally injects it into request bodies for SignIn.create, SignInFuture._create, and SignInFuture.password.
Sign-in tests
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
Adds tests asserting locale is included when navigator.language is set and excluded when empty; centralizes mock setup via beforeAll and resets mocks/unstubs in afterEach.
Test environment setup
packages/clerk-js/vitest.setup.mts
Sets window.navigator.language to an empty string ('') in the Vitest/jsdom setup.

Sequence Diagram(s)

sequenceDiagram
participant User
participant Browser
participant SignIn
participant Server
User->>SignIn: start sign-in (create / password)
SignIn->>Browser: getBrowserLocale()
alt locale detected
Browser-->>SignIn: "en-US" (example)
Note right of SignIn: include `locale` in request body
else locale not detected
Browser-->>SignIn: "" / undefined
Note right of SignIn: omit `locale` from request body
end
SignIn->>Server: POST /sign-in (body with/without locale)
Server-->>SignIn: response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I sniffed the browser breeze and found a clue,
I tucked the locale in the sign-in stew,
If silence whispered, I hopped away light,
The flow went on, tidy and right,
A tiny hop toward doing it true.

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title Check✅ PassedThe pull request title "feat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n)" is highly specific and accurately summarizes the main changes in the PR. It clearly communicates that the feature detects browser locale and sends it during sign-in, which aligns with all modifications across SignIn.ts, tests, and test setup. The title is concise, follows conventional commit formatting, and avoids vague terminology, making it immediately clear to reviewers what the core change accomplishes.
Linked Issues Check✅ PassedThe code changes fully satisfy the three primary objectives from USER-3712: locale detection from the browser is implemented via getBrowserLocale() [USER-3712], sending to the FAPI sign-in flow is accomplished by merging locale into the request body in SignIn.ts [USER-3712], and conditional sending without error handling is correctly implemented by only including locale when it is truthy [USER-3712]. The test suite validates both conditions—inclusion when navigator.language is set and exclusion when empty—confirming the implementation matches the requirements.
Out of Scope Changes Check✅ PassedAll changes in the pull request are directly related to the USER-3712 objective of detecting and sending browser locale during sign-in. The modifications to SignIn.ts implement the core feature, the test additions in SignIn.test.ts validate the locale detection and transmission, the changeset documents the new capability, and the vitest setup change provides test infrastructure support by mocking navigator.language. No unrelated refactoring, cleanup, or out-of-scope modifications are present.
Docstring Coverage✅ PassedNo 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 guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib

📜 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 f500017 and c781372.

📒 Files selected for processing (1)
  • packages/clerk-js/src/core/resources/SignIn.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/clerk-js/src/core/resources/SignIn.ts
⏰ 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

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

@pkg-pr-new

pkg-pr-newBot commented Oct 16, 2025

Copy link
Copy Markdown

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

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

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

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

@clerk/types

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

@clerk/upgrade

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

@clerk/vue

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

commit: c781372

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

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 160dc93 and 231a103.

📒 Files selected for processing (4)
  • .changeset/quick-kings-rescue.md (1 hunks)
  • packages/clerk-js/src/core/resources/SignIn.ts (4 hunks)
  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1 hunks)
  • packages/clerk-js/vitest.setup.mts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (10)
.changeset/**

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

Automated releases must use Changesets.

Files:

  • .changeset/quick-kings-rescue.md
**/*.{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/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.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/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
packages/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
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/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
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/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
**/__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/core/resources/__tests__/SignIn.test.ts
🧬 Code graph analysis (2)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)
packages/clerk-js/src/core/resources/SignIn.ts (1)
  • SignIn (99-556)
packages/clerk-js/src/core/resources/SignIn.ts (2)
packages/clerk-js/src/core/resources/SignUp.ts (1)
  • locale (650-652)
packages/clerk-js/src/utils/locale.ts (1)
  • getBrowserLocale (11-28)
⏰ 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). (2)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan


throw new Error('Unexpected call to BaseResource._fetch');
beforeAll(() => {
const signInCreatedJSON = {

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

with new tests and mocks, this was source of failing tests. So I just added moved the into the beforeAll function so we can have more control over order and scope

@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

since there is no change (even backwards compatible) to the sdk api for users, I think we have a patch here -- open to make it a minor as well

@guilherme6191guilherme6191 changed the title feat(i18n): at sign-in, detect locale from browser and send it to FAPI if existsfeat(i18n): At sign-in, detect locale from browser and send it to FAPI if existsOct 16, 2025
@guilherme6191guilherme6191 changed the title feat(i18n): At sign-in, detect locale from browser and send it to FAPI if existsfeat(i18n): Detect locale from browser and send it to FAPI if exists during sign-inOct 16, 2025
@guilherme6191

Copy link
Copy Markdown
ContributorAuthor

Note: I've labeled to do not merge for now as we need FAPI changes released - integration tests should fail because of that too.

return this._basePost({
path: this.pathRoot,
body: params,
body: { ...params, ...(locale ? { locale } : {}) },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe this order should be reversed, as we want to prefer the provided locale from params over the auto-detected one.

@guilherme6191guilherme6191Oct 16, 2025

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

@dstaley, good call. I'm updating the code as it's applicable in case we expose locale as a param as well, which is not the case now.

For now we're not exposing the locale to the sign-in API. We initially think that could add complexity for users and we'll revisit the DX if we expose it. It's available in sign-up as that's more appropriate there. Let me know if that makes sense.

FYI the functionality is going to be behind a FF too.

Comment thread.changeset/quick-kings-rescue.md Outdated
'@clerk/clerk-js': patch
---

Add browser locale to sign-in flow

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Add browser locale to sign-in flow
Add support for automatically sending the browser locale during the sign-in flow

@guilherme6191guilherme6191 changed the title feat(i18n): Detect locale from browser and send it to FAPI if exists during sign-infeat(clerk-js, i18n): Detect locale from browser and send it to FAPI if exists during sign-inOct 16, 2025
@guilherme6191
guilherme6191force-pushed the guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib branch from 7e714c7 to f500017CompareOctober 17, 2025 14:01

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

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 (1)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)

63-93: Consider adding cleanup for consistency.

The centralized mock setup in beforeAll is a good refactor. However, for consistency with the signIn.create suite and to prevent potential cross-suite pollution, consider adding an afterAll or afterEach to clear mocks after the SignInFuture tests complete.

 beforeAll(() => {
...
});
++ afterAll(() => {+ vi.clearAllMocks();+ });
it('should select correct first factor by email address', async () => {
📜 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 7e714c7 and f500017.

📒 Files selected for processing (4)
  • .changeset/quick-kings-rescue.md (1 hunks)
  • packages/clerk-js/src/core/resources/SignIn.ts (4 hunks)
  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1 hunks)
  • packages/clerk-js/vitest.setup.mts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • .changeset/quick-kings-rescue.md
  • packages/clerk-js/vitest.setup.mts
  • packages/clerk-js/src/core/resources/SignIn.ts
🧰 Additional context used
📓 Path-based instructions (9)
**/*.{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/core/resources/__tests__/SignIn.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/core/resources/__tests__/SignIn.test.ts
packages/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
**/__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/core/resources/__tests__/SignIn.test.ts
🧬 Code graph analysis (1)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)
packages/clerk-js/src/core/resources/SignIn.ts (1)
  • SignIn (99-556)
⏰ 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). (27)
  • GitHub Check: Integration Tests (billing, chrome)
  • GitHub Check: Integration Tests (machine, chrome)
  • GitHub Check: Integration Tests (custom, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 14)
  • GitHub Check: Integration Tests (handshake, chrome)
  • GitHub Check: Integration Tests (nuxt, chrome)
  • GitHub Check: Integration Tests (vue, chrome)
  • GitHub Check: Integration Tests (react-router, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 15)
  • GitHub Check: Integration Tests (sessions, chrome)
  • GitHub Check: Integration Tests (express, chrome)
  • GitHub Check: Integration Tests (astro, chrome)
  • GitHub Check: Integration Tests (sessions:staging, chrome)
  • GitHub Check: Integration Tests (tanstack-react-start, chrome)
  • GitHub Check: Integration Tests (localhost, chrome)
  • GitHub Check: Integration Tests (expo-web, chrome)
  • GitHub Check: Integration Tests (ap-flows, chrome)
  • GitHub Check: Integration Tests (handshake:staging, chrome)
  • GitHub Check: Integration Tests (quickstart, chrome)
  • GitHub Check: Integration Tests (elements, chrome)
  • GitHub Check: Integration Tests (generic, chrome)
  • GitHub Check: Static analysis
  • GitHub Check: Publish with pkg-pr-new
  • GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
  • GitHub Check: Unit Tests (22, **)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (1)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)

1-1: LGTM! Well-structured test suite for locale behavior.

The new test suite properly validates that:

  • Locale is included in the request body when navigator.language is set (test 1)
  • Locale is excluded when navigator.language is empty (test 2)

The cleanup in afterEach correctly addresses the past review concern about stubbed globals persisting across tests.

Also applies to: 7-59

@guilherme6191guilherme6191 changed the title feat(clerk-js, i18n): Detect locale from browser and send it to FAPI if exists during sign-infeat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n)Oct 17, 2025
Comment threadpackages/clerk-js/src/core/resources/SignIn.ts Outdated
Comment threadpackages/clerk-js/src/core/resources/SignIn.ts Outdated
@guilherme6191
guilherme6191 merged commit 6503405 into mainOct 17, 2025
41 checks passed
@guilherme6191
guilherme6191 deleted the guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib branch October 17, 2025 16:34
NicolasLopes7 pushed a commit that referenced this pull request Oct 23, 2025
Sign up for freeto 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

@guilherme6191@tmilewski@dstaley@clerk-cookie
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

feat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n) - #7011

Merged
guilherme6191 merged 6 commits into
mainfrom
guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib
Oct 17, 2025
Merged

feat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n)#7011
guilherme6191 merged 6 commits into
mainfrom
guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib

Conversation

@guilherme6191

@guilherme6191guilherme6191 commented Oct 16, 2025

Copy link
Copy Markdown
Contributor

Description

This PR adds auto detection of browser locale (navigator.language) and sends that to sign-in flow. This is similar to the behavior implemented for the sign-up (#6915), but does not expose locale in the API to reduce noise/complexity at sign-in for now.

For extra context: this is a change where we'll be storing users preferred language from the browser, and C1s can update via BAPI (later on via dashboard and AIOs) so we can send localized templates. The whole feature is behind a FF and we're rolling out only for Spark (new customer implementing Clerk).

https://linear.app/clerk/issue/USER-3712/detect-and-send-locale-in-sign-ins-js-lib

Note: needs https://github.com/clerk/clerk_go/pull/14182 released

Checklist

Type of change

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

Summary by CodeRabbit

  • New Features

    • Sign-in flow now detects and automatically sends the browser locale to improve localization during authentication.
  • Tests

    • Added tests verifying locale is included when present and omitted when absent.
    • Test setup updated for a predictable navigator.language and centralized mock/cleanup to stabilize sign-in test suites.

@changeset-bot

changeset-botBot commented Oct 16, 2025

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c781372

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

This PR includes changesets to release 3 packages
NameType
@clerk/clerk-jsPatch
@clerk/chrome-extensionPatch
@clerk/clerk-expoPatch

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

@vercel

vercelBot commented Oct 16, 2025

Copy link
Copy Markdown

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

ProjectDeploymentPreviewCommentsUpdated (UTC)
clerk-js-sandboxReadyReadyPreviewCommentOct 17, 2025 4:21pm

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

@coderabbitai

coderabbitaiBot commented Oct 16, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Adds browser locale detection to the @clerk/clerk-js sign-in flow by calling getBrowserLocale() and conditionally including the locale in sign-in request bodies; if no locale is detected, requests omit the locale.

Changes

Cohort / File(s)Summary
Changeset documentation
​.changeset/quick-kings-rescue.md
Patch release entry noting addition of browser locale to sign-in flow.
Sign-in implementation
packages/clerk-js/src/core/resources/SignIn.ts
Computes locale via getBrowserLocale() and conditionally injects it into request bodies for SignIn.create, SignInFuture._create, and SignInFuture.password.
Sign-in tests
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
Adds tests asserting locale is included when navigator.language is set and excluded when empty; centralizes mock setup via beforeAll and resets mocks/unstubs in afterEach.
Test environment setup
packages/clerk-js/vitest.setup.mts
Sets window.navigator.language to an empty string ('') in the Vitest/jsdom setup.

Sequence Diagram(s)

sequenceDiagram
participant User
participant Browser
participant SignIn
participant Server
User->>SignIn: start sign-in (create / password)
SignIn->>Browser: getBrowserLocale()
alt locale detected
Browser-->>SignIn: "en-US" (example)
Note right of SignIn: include `locale` in request body
else locale not detected
Browser-->>SignIn: "" / undefined
Note right of SignIn: omit `locale` from request body
end
SignIn->>Server: POST /sign-in (body with/without locale)
Server-->>SignIn: response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I sniffed the browser breeze and found a clue,
I tucked the locale in the sign-in stew,
If silence whispered, I hopped away light,
The flow went on, tidy and right,
A tiny hop toward doing it true.

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title Check✅ PassedThe pull request title "feat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n)" is highly specific and accurately summarizes the main changes in the PR. It clearly communicates that the feature detects browser locale and sends it during sign-in, which aligns with all modifications across SignIn.ts, tests, and test setup. The title is concise, follows conventional commit formatting, and avoids vague terminology, making it immediately clear to reviewers what the core change accomplishes.
Linked Issues Check✅ PassedThe code changes fully satisfy the three primary objectives from USER-3712: locale detection from the browser is implemented via getBrowserLocale() [USER-3712], sending to the FAPI sign-in flow is accomplished by merging locale into the request body in SignIn.ts [USER-3712], and conditional sending without error handling is correctly implemented by only including locale when it is truthy [USER-3712]. The test suite validates both conditions—inclusion when navigator.language is set and exclusion when empty—confirming the implementation matches the requirements.
Out of Scope Changes Check✅ PassedAll changes in the pull request are directly related to the USER-3712 objective of detecting and sending browser locale during sign-in. The modifications to SignIn.ts implement the core feature, the test additions in SignIn.test.ts validate the locale detection and transmission, the changeset documents the new capability, and the vitest setup change provides test infrastructure support by mocking navigator.language. No unrelated refactoring, cleanup, or out-of-scope modifications are present.
Docstring Coverage✅ PassedNo 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 guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib

📜 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 f500017 and c781372.

📒 Files selected for processing (1)
  • packages/clerk-js/src/core/resources/SignIn.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/clerk-js/src/core/resources/SignIn.ts
⏰ 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

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

@pkg-pr-new

pkg-pr-newBot commented Oct 16, 2025

Copy link
Copy Markdown

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

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

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

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

@clerk/types

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

@clerk/upgrade

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

@clerk/vue

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

commit: c781372

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

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 160dc93 and 231a103.

📒 Files selected for processing (4)
  • .changeset/quick-kings-rescue.md (1 hunks)
  • packages/clerk-js/src/core/resources/SignIn.ts (4 hunks)
  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1 hunks)
  • packages/clerk-js/vitest.setup.mts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (10)
.changeset/**

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

Automated releases must use Changesets.

Files:

  • .changeset/quick-kings-rescue.md
**/*.{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/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.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/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
packages/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
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/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
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/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
**/__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/core/resources/__tests__/SignIn.test.ts
🧬 Code graph analysis (2)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)
packages/clerk-js/src/core/resources/SignIn.ts (1)
  • SignIn (99-556)
packages/clerk-js/src/core/resources/SignIn.ts (2)
packages/clerk-js/src/core/resources/SignUp.ts (1)
  • locale (650-652)
packages/clerk-js/src/utils/locale.ts (1)
  • getBrowserLocale (11-28)
⏰ 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). (2)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan


throw new Error('Unexpected call to BaseResource._fetch');
beforeAll(() => {
const signInCreatedJSON = {

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

with new tests and mocks, this was source of failing tests. So I just added moved the into the beforeAll function so we can have more control over order and scope

@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

since there is no change (even backwards compatible) to the sdk api for users, I think we have a patch here -- open to make it a minor as well

@guilherme6191guilherme6191 changed the title feat(i18n): at sign-in, detect locale from browser and send it to FAPI if existsfeat(i18n): At sign-in, detect locale from browser and send it to FAPI if existsOct 16, 2025
@guilherme6191guilherme6191 changed the title feat(i18n): At sign-in, detect locale from browser and send it to FAPI if existsfeat(i18n): Detect locale from browser and send it to FAPI if exists during sign-inOct 16, 2025
@guilherme6191

Copy link
Copy Markdown
ContributorAuthor

Note: I've labeled to do not merge for now as we need FAPI changes released - integration tests should fail because of that too.

return this._basePost({
path: this.pathRoot,
body: params,
body: { ...params, ...(locale ? { locale } : {}) },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe this order should be reversed, as we want to prefer the provided locale from params over the auto-detected one.

@guilherme6191guilherme6191Oct 16, 2025

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

@dstaley, good call. I'm updating the code as it's applicable in case we expose locale as a param as well, which is not the case now.

For now we're not exposing the locale to the sign-in API. We initially think that could add complexity for users and we'll revisit the DX if we expose it. It's available in sign-up as that's more appropriate there. Let me know if that makes sense.

FYI the functionality is going to be behind a FF too.

Comment thread.changeset/quick-kings-rescue.md Outdated
'@clerk/clerk-js': patch
---

Add browser locale to sign-in flow

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Add browser locale to sign-in flow
Add support for automatically sending the browser locale during the sign-in flow

@guilherme6191guilherme6191 changed the title feat(i18n): Detect locale from browser and send it to FAPI if exists during sign-infeat(clerk-js, i18n): Detect locale from browser and send it to FAPI if exists during sign-inOct 16, 2025
@guilherme6191
guilherme6191force-pushed the guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib branch from 7e714c7 to f500017CompareOctober 17, 2025 14:01

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

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 (1)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)

63-93: Consider adding cleanup for consistency.

The centralized mock setup in beforeAll is a good refactor. However, for consistency with the signIn.create suite and to prevent potential cross-suite pollution, consider adding an afterAll or afterEach to clear mocks after the SignInFuture tests complete.

 beforeAll(() => {
...
});
++ afterAll(() => {+ vi.clearAllMocks();+ });
it('should select correct first factor by email address', async () => {
📜 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 7e714c7 and f500017.

📒 Files selected for processing (4)
  • .changeset/quick-kings-rescue.md (1 hunks)
  • packages/clerk-js/src/core/resources/SignIn.ts (4 hunks)
  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1 hunks)
  • packages/clerk-js/vitest.setup.mts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • .changeset/quick-kings-rescue.md
  • packages/clerk-js/vitest.setup.mts
  • packages/clerk-js/src/core/resources/SignIn.ts
🧰 Additional context used
📓 Path-based instructions (9)
**/*.{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/core/resources/__tests__/SignIn.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/core/resources/__tests__/SignIn.test.ts
packages/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
**/__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/core/resources/__tests__/SignIn.test.ts
🧬 Code graph analysis (1)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)
packages/clerk-js/src/core/resources/SignIn.ts (1)
  • SignIn (99-556)
⏰ 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). (27)
  • GitHub Check: Integration Tests (billing, chrome)
  • GitHub Check: Integration Tests (machine, chrome)
  • GitHub Check: Integration Tests (custom, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 14)
  • GitHub Check: Integration Tests (handshake, chrome)
  • GitHub Check: Integration Tests (nuxt, chrome)
  • GitHub Check: Integration Tests (vue, chrome)
  • GitHub Check: Integration Tests (react-router, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 15)
  • GitHub Check: Integration Tests (sessions, chrome)
  • GitHub Check: Integration Tests (express, chrome)
  • GitHub Check: Integration Tests (astro, chrome)
  • GitHub Check: Integration Tests (sessions:staging, chrome)
  • GitHub Check: Integration Tests (tanstack-react-start, chrome)
  • GitHub Check: Integration Tests (localhost, chrome)
  • GitHub Check: Integration Tests (expo-web, chrome)
  • GitHub Check: Integration Tests (ap-flows, chrome)
  • GitHub Check: Integration Tests (handshake:staging, chrome)
  • GitHub Check: Integration Tests (quickstart, chrome)
  • GitHub Check: Integration Tests (elements, chrome)
  • GitHub Check: Integration Tests (generic, chrome)
  • GitHub Check: Static analysis
  • GitHub Check: Publish with pkg-pr-new
  • GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
  • GitHub Check: Unit Tests (22, **)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (1)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)

1-1: LGTM! Well-structured test suite for locale behavior.

The new test suite properly validates that:

  • Locale is included in the request body when navigator.language is set (test 1)
  • Locale is excluded when navigator.language is empty (test 2)

The cleanup in afterEach correctly addresses the past review concern about stubbed globals persisting across tests.

Also applies to: 7-59

@guilherme6191guilherme6191 changed the title feat(clerk-js, i18n): Detect locale from browser and send it to FAPI if exists during sign-infeat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n)Oct 17, 2025
Comment threadpackages/clerk-js/src/core/resources/SignIn.ts Outdated
Comment threadpackages/clerk-js/src/core/resources/SignIn.ts Outdated
@guilherme6191
guilherme6191 merged commit 6503405 into mainOct 17, 2025
41 checks passed
@guilherme6191
guilherme6191 deleted the guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib branch October 17, 2025 16:34
NicolasLopes7 pushed a commit that referenced this pull request Oct 23, 2025
Sign up for freeto 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

@guilherme6191@tmilewski@dstaley@clerk-cookie
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

feat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n) - #7011

Merged
guilherme6191 merged 6 commits into
mainfrom
guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib
Oct 17, 2025
Merged

feat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n)#7011
guilherme6191 merged 6 commits into
mainfrom
guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib

Conversation

@guilherme6191

@guilherme6191guilherme6191 commented Oct 16, 2025

Copy link
Copy Markdown
Contributor

Description

This PR adds auto detection of browser locale (navigator.language) and sends that to sign-in flow. This is similar to the behavior implemented for the sign-up (#6915), but does not expose locale in the API to reduce noise/complexity at sign-in for now.

For extra context: this is a change where we'll be storing users preferred language from the browser, and C1s can update via BAPI (later on via dashboard and AIOs) so we can send localized templates. The whole feature is behind a FF and we're rolling out only for Spark (new customer implementing Clerk).

https://linear.app/clerk/issue/USER-3712/detect-and-send-locale-in-sign-ins-js-lib

Note: needs https://github.com/clerk/clerk_go/pull/14182 released

Checklist

Type of change

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

Summary by CodeRabbit

  • New Features

    • Sign-in flow now detects and automatically sends the browser locale to improve localization during authentication.
  • Tests

    • Added tests verifying locale is included when present and omitted when absent.
    • Test setup updated for a predictable navigator.language and centralized mock/cleanup to stabilize sign-in test suites.

@changeset-bot

changeset-botBot commented Oct 16, 2025

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c781372

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

This PR includes changesets to release 3 packages
NameType
@clerk/clerk-jsPatch
@clerk/chrome-extensionPatch
@clerk/clerk-expoPatch

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

@vercel

vercelBot commented Oct 16, 2025

Copy link
Copy Markdown

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

ProjectDeploymentPreviewCommentsUpdated (UTC)
clerk-js-sandboxReadyReadyPreviewCommentOct 17, 2025 4:21pm

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

@coderabbitai

coderabbitaiBot commented Oct 16, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Adds browser locale detection to the @clerk/clerk-js sign-in flow by calling getBrowserLocale() and conditionally including the locale in sign-in request bodies; if no locale is detected, requests omit the locale.

Changes

Cohort / File(s)Summary
Changeset documentation
​.changeset/quick-kings-rescue.md
Patch release entry noting addition of browser locale to sign-in flow.
Sign-in implementation
packages/clerk-js/src/core/resources/SignIn.ts
Computes locale via getBrowserLocale() and conditionally injects it into request bodies for SignIn.create, SignInFuture._create, and SignInFuture.password.
Sign-in tests
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
Adds tests asserting locale is included when navigator.language is set and excluded when empty; centralizes mock setup via beforeAll and resets mocks/unstubs in afterEach.
Test environment setup
packages/clerk-js/vitest.setup.mts
Sets window.navigator.language to an empty string ('') in the Vitest/jsdom setup.

Sequence Diagram(s)

sequenceDiagram
participant User
participant Browser
participant SignIn
participant Server
User->>SignIn: start sign-in (create / password)
SignIn->>Browser: getBrowserLocale()
alt locale detected
Browser-->>SignIn: "en-US" (example)
Note right of SignIn: include `locale` in request body
else locale not detected
Browser-->>SignIn: "" / undefined
Note right of SignIn: omit `locale` from request body
end
SignIn->>Server: POST /sign-in (body with/without locale)
Server-->>SignIn: response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I sniffed the browser breeze and found a clue,
I tucked the locale in the sign-in stew,
If silence whispered, I hopped away light,
The flow went on, tidy and right,
A tiny hop toward doing it true.

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title Check✅ PassedThe pull request title "feat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n)" is highly specific and accurately summarizes the main changes in the PR. It clearly communicates that the feature detects browser locale and sends it during sign-in, which aligns with all modifications across SignIn.ts, tests, and test setup. The title is concise, follows conventional commit formatting, and avoids vague terminology, making it immediately clear to reviewers what the core change accomplishes.
Linked Issues Check✅ PassedThe code changes fully satisfy the three primary objectives from USER-3712: locale detection from the browser is implemented via getBrowserLocale() [USER-3712], sending to the FAPI sign-in flow is accomplished by merging locale into the request body in SignIn.ts [USER-3712], and conditional sending without error handling is correctly implemented by only including locale when it is truthy [USER-3712]. The test suite validates both conditions—inclusion when navigator.language is set and exclusion when empty—confirming the implementation matches the requirements.
Out of Scope Changes Check✅ PassedAll changes in the pull request are directly related to the USER-3712 objective of detecting and sending browser locale during sign-in. The modifications to SignIn.ts implement the core feature, the test additions in SignIn.test.ts validate the locale detection and transmission, the changeset documents the new capability, and the vitest setup change provides test infrastructure support by mocking navigator.language. No unrelated refactoring, cleanup, or out-of-scope modifications are present.
Docstring Coverage✅ PassedNo 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 guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib

📜 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 f500017 and c781372.

📒 Files selected for processing (1)
  • packages/clerk-js/src/core/resources/SignIn.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/clerk-js/src/core/resources/SignIn.ts
⏰ 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

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

@pkg-pr-new

pkg-pr-newBot commented Oct 16, 2025

Copy link
Copy Markdown

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

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

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

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

@clerk/types

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

@clerk/upgrade

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

@clerk/vue

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

commit: c781372

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

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 160dc93 and 231a103.

📒 Files selected for processing (4)
  • .changeset/quick-kings-rescue.md (1 hunks)
  • packages/clerk-js/src/core/resources/SignIn.ts (4 hunks)
  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1 hunks)
  • packages/clerk-js/vitest.setup.mts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (10)
.changeset/**

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

Automated releases must use Changesets.

Files:

  • .changeset/quick-kings-rescue.md
**/*.{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/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.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/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
packages/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
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/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
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/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
**/__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/core/resources/__tests__/SignIn.test.ts
🧬 Code graph analysis (2)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)
packages/clerk-js/src/core/resources/SignIn.ts (1)
  • SignIn (99-556)
packages/clerk-js/src/core/resources/SignIn.ts (2)
packages/clerk-js/src/core/resources/SignUp.ts (1)
  • locale (650-652)
packages/clerk-js/src/utils/locale.ts (1)
  • getBrowserLocale (11-28)
⏰ 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). (2)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan


throw new Error('Unexpected call to BaseResource._fetch');
beforeAll(() => {
const signInCreatedJSON = {

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

with new tests and mocks, this was source of failing tests. So I just added moved the into the beforeAll function so we can have more control over order and scope

@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

since there is no change (even backwards compatible) to the sdk api for users, I think we have a patch here -- open to make it a minor as well

@guilherme6191guilherme6191 changed the title feat(i18n): at sign-in, detect locale from browser and send it to FAPI if existsfeat(i18n): At sign-in, detect locale from browser and send it to FAPI if existsOct 16, 2025
@guilherme6191guilherme6191 changed the title feat(i18n): At sign-in, detect locale from browser and send it to FAPI if existsfeat(i18n): Detect locale from browser and send it to FAPI if exists during sign-inOct 16, 2025
@guilherme6191

Copy link
Copy Markdown
ContributorAuthor

Note: I've labeled to do not merge for now as we need FAPI changes released - integration tests should fail because of that too.

return this._basePost({
path: this.pathRoot,
body: params,
body: { ...params, ...(locale ? { locale } : {}) },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe this order should be reversed, as we want to prefer the provided locale from params over the auto-detected one.

@guilherme6191guilherme6191Oct 16, 2025

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

@dstaley, good call. I'm updating the code as it's applicable in case we expose locale as a param as well, which is not the case now.

For now we're not exposing the locale to the sign-in API. We initially think that could add complexity for users and we'll revisit the DX if we expose it. It's available in sign-up as that's more appropriate there. Let me know if that makes sense.

FYI the functionality is going to be behind a FF too.

Comment thread.changeset/quick-kings-rescue.md Outdated
'@clerk/clerk-js': patch
---

Add browser locale to sign-in flow

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Add browser locale to sign-in flow
Add support for automatically sending the browser locale during the sign-in flow

@guilherme6191guilherme6191 changed the title feat(i18n): Detect locale from browser and send it to FAPI if exists during sign-infeat(clerk-js, i18n): Detect locale from browser and send it to FAPI if exists during sign-inOct 16, 2025
@guilherme6191
guilherme6191force-pushed the guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib branch from 7e714c7 to f500017CompareOctober 17, 2025 14:01

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

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 (1)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)

63-93: Consider adding cleanup for consistency.

The centralized mock setup in beforeAll is a good refactor. However, for consistency with the signIn.create suite and to prevent potential cross-suite pollution, consider adding an afterAll or afterEach to clear mocks after the SignInFuture tests complete.

 beforeAll(() => {
...
});
++ afterAll(() => {+ vi.clearAllMocks();+ });
it('should select correct first factor by email address', async () => {
📜 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 7e714c7 and f500017.

📒 Files selected for processing (4)
  • .changeset/quick-kings-rescue.md (1 hunks)
  • packages/clerk-js/src/core/resources/SignIn.ts (4 hunks)
  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1 hunks)
  • packages/clerk-js/vitest.setup.mts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • .changeset/quick-kings-rescue.md
  • packages/clerk-js/vitest.setup.mts
  • packages/clerk-js/src/core/resources/SignIn.ts
🧰 Additional context used
📓 Path-based instructions (9)
**/*.{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/core/resources/__tests__/SignIn.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/core/resources/__tests__/SignIn.test.ts
packages/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.test.ts
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/core/resources/__tests__/SignIn.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:

  • packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts
**/__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/core/resources/__tests__/SignIn.test.ts
🧬 Code graph analysis (1)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)
packages/clerk-js/src/core/resources/SignIn.ts (1)
  • SignIn (99-556)
⏰ 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). (27)
  • GitHub Check: Integration Tests (billing, chrome)
  • GitHub Check: Integration Tests (machine, chrome)
  • GitHub Check: Integration Tests (custom, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 14)
  • GitHub Check: Integration Tests (handshake, chrome)
  • GitHub Check: Integration Tests (nuxt, chrome)
  • GitHub Check: Integration Tests (vue, chrome)
  • GitHub Check: Integration Tests (react-router, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 15)
  • GitHub Check: Integration Tests (sessions, chrome)
  • GitHub Check: Integration Tests (express, chrome)
  • GitHub Check: Integration Tests (astro, chrome)
  • GitHub Check: Integration Tests (sessions:staging, chrome)
  • GitHub Check: Integration Tests (tanstack-react-start, chrome)
  • GitHub Check: Integration Tests (localhost, chrome)
  • GitHub Check: Integration Tests (expo-web, chrome)
  • GitHub Check: Integration Tests (ap-flows, chrome)
  • GitHub Check: Integration Tests (handshake:staging, chrome)
  • GitHub Check: Integration Tests (quickstart, chrome)
  • GitHub Check: Integration Tests (elements, chrome)
  • GitHub Check: Integration Tests (generic, chrome)
  • GitHub Check: Static analysis
  • GitHub Check: Publish with pkg-pr-new
  • GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
  • GitHub Check: Unit Tests (22, **)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (1)
packages/clerk-js/src/core/resources/__tests__/SignIn.test.ts (1)

1-1: LGTM! Well-structured test suite for locale behavior.

The new test suite properly validates that:

  • Locale is included in the request body when navigator.language is set (test 1)
  • Locale is excluded when navigator.language is empty (test 2)

The cleanup in afterEach correctly addresses the past review concern about stubbed globals persisting across tests.

Also applies to: 7-59

@guilherme6191guilherme6191 changed the title feat(clerk-js, i18n): Detect locale from browser and send it to FAPI if exists during sign-infeat(clerk-js): Detect locale from browser and send it to FAPI if exists during sign-in (i18n)Oct 17, 2025
Comment threadpackages/clerk-js/src/core/resources/SignIn.ts Outdated
Comment threadpackages/clerk-js/src/core/resources/SignIn.ts Outdated
@guilherme6191
guilherme6191 merged commit 6503405 into mainOct 17, 2025
41 checks passed
@guilherme6191
guilherme6191 deleted the guilherme/user-3712-detect-and-send-locale-in-sign-ins-js-lib branch October 17, 2025 16:34
NicolasLopes7 pushed a commit that referenced this pull request Oct 23, 2025
Sign up for freeto 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

@guilherme6191@tmilewski@dstaley@clerk-cookie