Skip to content

Conversation

guilherme6191
Copy link
Member

@guilherme6191 guilherme6191 commented Oct 3, 2025

Description

This PR adds locale to signup flow. If it's not passed by users, we retrieve it from the browser. If the value we get from the browser can be determined (trying to narrow it down to BPC 147 spec), we don't infer and set the default to null.

Related PRs for extra context, if needed:

Note: this shouldn't have issues in Expo (the inferring) , but we might want to explore expo-localization in the future or as a follow-up for a expo specific solution.

https://linear.app/clerk/issue/USER-3606/retrieve-and-send-locale-information-with-sign-ups

Checklist

  • generate changeset

  • pnpm test runs as expected.

  • pnpm build runs as expected.

  • (If applicable) JSDoc comments have been added or updated for any package exports

  • (If applicable) Documentation has been updated

Type of change

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

Summary by CodeRabbit

  • New Features

    • Sign-up now accepts, persists and exposes a locale value; browser locale is used automatically if none provided.
  • Tests

    • Added unit tests covering browser locale detection across multiple scenarios.
  • Documentation

    • Playground README updated to use localhost:4011.
  • Chores

    • Broadened .env ignore rules, ignored Clerk config dir, added locale utilities to exports, and updated test fixtures to include locale.

Copy link

changeset-bot bot commented Oct 3, 2025

⚠️ No Changeset found

Latest commit: b247d8a

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

This PR includes no changesets

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

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

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

Copy link

vercel bot commented Oct 3, 2025

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

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

Copy link
Contributor

coderabbitai bot commented Oct 3, 2025

Walkthrough

Adds browser-derived locale support for sign-ups: new getBrowserLocale utility and tests; locale field added to SignUp/SignUpFuture, types, JSON and fixtures; SignUp.create/SignUpFuture.create inject locale when missing; minor playground updates.

Changes

Cohort / File(s) Summary
SignUp locale integration
packages/clerk-js/src/core/resources/SignUp.ts
Adds public locale: string | null; fromJSON/snapshot read/serialize locale; SignUp.create and SignUpFuture.create derive locale from params.locale or getBrowserLocale() and include it in request payloads.
Locale utility + tests + re-export
packages/clerk-js/src/utils/locale.ts, packages/clerk-js/src/utils/index.ts, packages/clerk-js/src/utils/__tests__/locale.test.ts
New getBrowserLocale(): string | null using inBrowser and navigator.language; re-exported from utils index; tests cover present/undefined/empty/missing navigator.
Types: SignUp resource and params
packages/types/src/signUp.ts, packages/types/src/signUpCommon.ts, packages/types/src/signUpFuture.ts, packages/types/src/json.ts
Adds locale: string | null to SignUpResource/SignUpJSON; optional locale?: string to SignUpCreateParams and SignUpFutureAdditionalParams; adds locale to future resource types.
Test fixtures
packages/clerk-js/src/test/core-fixtures.ts
createSignUp fixture now populates legal_accepted_at and locale from params in produced SignUpJSON.
React state proxy
packages/react/src/stateProxy.ts
Added locale getter on signUp proxy exposing locale via gateProperty(target, 'locale', null).
Playground housekeeping
playground/app-router/.gitignore, playground/app-router/README.md
.gitignore updated to ignore .env* and /.clerk/; README example URLs updated from localhost:3000 to localhost:4011.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant UI as App UI
  participant Client as SignUp client
  participant Util as getBrowserLocale()
  participant API as Backend API

  User->>UI: Submit sign-up (params may omit locale)
  UI->>Client: SignUp.create(params)
  alt params.locale provided
    Client->>API: POST /sign-ups { ..., locale }
  else params.locale missing
    Client->>Util: getBrowserLocale()
    Util-->>Client: locale \| null
    Client->>API: POST /sign-ups { ..., locale? }
  end
  API-->>Client: 201 Created { locale }
  Client-->>UI: SignUpResource { locale }
Loading
sequenceDiagram
  autonumber
  actor User
  participant UI as App UI
  participant Future as SignUpFuture
  participant Util as getBrowserLocale()
  participant API as Backend API

  User->>UI: Start future sign-up
  UI->>Future: SignUpFuture.create(params?)
  alt params.locale missing
    Future->>Util: getBrowserLocale()
    Util-->>Future: locale \| null
  end
  Future->>API: POST /sign-ups { ..., locale? }
  API-->>Future: 201 Created { locale }
  Future-->>UI: Future result with locale
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I twitch my whiskers, listen near,
I seek the tongue your browser bears.
If none is found, I gently peep—
I tuck the locale into sign-up deep. 🐰🌍

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning This changeset includes modifications to the playground/app-router .gitignore and README files and the addition of legal_accepted_at in the test fixtures, which fall outside the scoped objective of retrieving and sending locale information during sign-ups. Please separate the playground configuration updates and the legal_accepted_at fixture addition into a different pull request or remove them from this changeset so that the PR remains focused solely on locale retrieval and propagation in the signup flow.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed Title concisely summarizes the addition of optional locale retrieval from the browser to the signup flow across the clerk-js and types packages, matching the primary change in the pull request.
Linked Issues Check ✅ Passed The pull request implements a getBrowserLocale utility, integrates locale propagation in SignUp and SignUpFuture create flows, and updates the related type definitions so that browser locale is captured and sent only during sign-up flows, fully aligning with the USER-3606 objectives.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ 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-3606-retrieve-and-send-locale-information-with-sign-ups

📜 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 93c8d23 and b247d8a.

📒 Files selected for processing (2)
  • packages/clerk-js/src/core/resources/SignUp.ts (7 hunks)
  • packages/clerk-js/src/utils/locale.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/clerk-js/src/core/resources/SignUp.ts
  • packages/clerk-js/src/utils/locale.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). (6)
  • GitHub Check: Build Packages
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: semgrep/ci
  • 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.

@guilherme6191 guilherme6191 changed the title feat: Add optional locale frowm browser to signup flow feat(clerk-js, types): Add optional locale frowm browser to signup flow Oct 3, 2025
@guilherme6191 guilherme6191 self-assigned this Oct 3, 2025
Copy link
Member

@tmilewski tmilewski left a comment

Choose a reason for hiding this comment

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

This is looking good, but holding off on approving as we'll need to get the supporting work in.

@guilherme6191 guilherme6191 force-pushed the guilherme/user-3606-retrieve-and-send-locale-information-with-sign-ups branch from 5f02d05 to 1cf759a Compare October 6, 2025 21:18
@guilherme6191 guilherme6191 changed the title feat(clerk-js, types): Add optional locale frowm browser to signup flow feat(clerk-js, types): Add optional locale from browser to signup flow Oct 7, 2025
@guilherme6191 guilherme6191 force-pushed the guilherme/user-3606-retrieve-and-send-locale-information-with-sign-ups branch from 1cf759a to c3c3ba3 Compare October 8, 2025 19:45
@guilherme6191 guilherme6191 marked this pull request as ready for review October 8, 2025 20:00
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

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

⚠️ Outside diff range comments (2)
packages/clerk-js/src/core/resources/SignUp.ts (2)

466-491: Missing locale deserialization in fromJSON.

The fromJSON method does not populate this.locale from the API response data. This means the locale value will be lost when the SignUp object is reconstructed from JSON (e.g., after page refresh or state rehydration).

Add locale deserialization:

 protected fromJSON(data: SignUpJSON | SignUpJSONSnapshot | null): this {
   if (data) {
     this.id = data.id;
     this.status = data.status;
     this.requiredFields = data.required_fields;
     this.optionalFields = data.optional_fields;
     this.missingFields = data.missing_fields;
     this.unverifiedFields = data.unverified_fields;
     this.verifications = new SignUpVerifications(data.verifications);
     this.username = data.username;
     this.firstName = data.first_name;
     this.lastName = data.last_name;
     this.emailAddress = data.email_address;
     this.phoneNumber = data.phone_number;
     this.hasPassword = data.has_password;
     this.unsafeMetadata = data.unsafe_metadata;
     this.createdSessionId = data.created_session_id;
     this.createdUserId = data.created_user_id;
     this.abandonAt = data.abandon_at;
     this.web3wallet = data.web3_wallet;
     this.legalAcceptedAt = data.legal_accepted_at;
+    this.locale = data.locale;
   }

   eventBus.emit('resource:update', { resource: this });
   return this;
 }

493-518: Missing locale serialization in __internal_toSnapshot.

The __internal_toSnapshot method does not include the locale field in the returned snapshot. This will prevent the locale from being persisted in state management and cause data loss during serialization.

Add locale to the snapshot:

 public __internal_toSnapshot(): SignUpJSONSnapshot {
   return {
     object: 'sign_up',
     id: this.id || '',
     status: this.status || null,
     required_fields: this.requiredFields,
     optional_fields: this.optionalFields,
     missing_fields: this.missingFields,
     unverified_fields: this.unverifiedFields,
     verifications: this.verifications.__internal_toSnapshot(),
     username: this.username,
     first_name: this.firstName,
     last_name: this.lastName,
     email_address: this.emailAddress,
     phone_number: this.phoneNumber,
     has_password: this.hasPassword,
     unsafe_metadata: this.unsafeMetadata,
     created_session_id: this.createdSessionId,
     created_user_id: this.createdUserId,
     abandon_at: this.abandonAt,
     web3_wallet: this.web3wallet,
     legal_accepted_at: this.legalAcceptedAt,
+    locale: this.locale,
     external_account: this.externalAccount,
     external_account_strategy: this.externalAccount?.strategy,
   };
 }
📜 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 7edaa7a and c3c3ba3.

📒 Files selected for processing (9)
  • packages/clerk-js/src/core/resources/SignUp.ts (4 hunks)
  • packages/clerk-js/src/utils/__tests__/locale.test.ts (1 hunks)
  • packages/clerk-js/src/utils/index.ts (1 hunks)
  • packages/clerk-js/src/utils/locale.ts (1 hunks)
  • packages/types/src/signUp.ts (1 hunks)
  • packages/types/src/signUpCommon.ts (1 hunks)
  • packages/types/src/signUpFuture.ts (1 hunks)
  • playground/app-router/.gitignore (1 hunks)
  • playground/app-router/README.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (13)
**/*.{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/utils/index.ts
  • packages/clerk-js/src/utils/locale.ts
  • packages/types/src/signUpCommon.ts
  • packages/types/src/signUpFuture.ts
  • packages/clerk-js/src/core/resources/SignUp.ts
  • packages/clerk-js/src/utils/__tests__/locale.test.ts
  • packages/types/src/signUp.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/utils/index.ts
  • packages/clerk-js/src/utils/locale.ts
  • packages/types/src/signUpCommon.ts
  • packages/types/src/signUpFuture.ts
  • packages/clerk-js/src/core/resources/SignUp.ts
  • playground/app-router/README.md
  • packages/clerk-js/src/utils/__tests__/locale.test.ts
  • packages/types/src/signUp.ts
packages/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/utils/index.ts
  • packages/clerk-js/src/utils/locale.ts
  • packages/types/src/signUpCommon.ts
  • packages/types/src/signUpFuture.ts
  • packages/clerk-js/src/core/resources/SignUp.ts
  • packages/clerk-js/src/utils/__tests__/locale.test.ts
  • packages/types/src/signUp.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/utils/index.ts
  • packages/clerk-js/src/utils/locale.ts
  • packages/types/src/signUpCommon.ts
  • packages/types/src/signUpFuture.ts
  • packages/clerk-js/src/core/resources/SignUp.ts
  • packages/clerk-js/src/utils/__tests__/locale.test.ts
  • packages/types/src/signUp.ts
packages/**/index.{js,ts}

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

Use tree-shaking friendly exports

Files:

  • packages/clerk-js/src/utils/index.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/utils/index.ts
  • packages/clerk-js/src/utils/locale.ts
  • packages/types/src/signUpCommon.ts
  • packages/types/src/signUpFuture.ts
  • packages/clerk-js/src/core/resources/SignUp.ts
  • packages/clerk-js/src/utils/__tests__/locale.test.ts
  • packages/types/src/signUp.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/utils/index.ts
  • packages/clerk-js/src/utils/locale.ts
  • packages/types/src/signUpCommon.ts
  • packages/types/src/signUpFuture.ts
  • packages/clerk-js/src/core/resources/SignUp.ts
  • packages/clerk-js/src/utils/__tests__/locale.test.ts
  • packages/types/src/signUp.ts
**/index.ts

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

Use index.ts files for clean imports but avoid deep barrel exports

Avoid barrel files (index.ts re-exports) as they can cause circular dependencies

Files:

  • packages/clerk-js/src/utils/index.ts
playground/**

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

Development and testing applications should be placed under the playground/ directory

Files:

  • playground/app-router/README.md
playground/**/*

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

Development and testing applications must be located in the 'playground/' directory.

Files:

  • playground/app-router/README.md
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/utils/__tests__/locale.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/utils/__tests__/locale.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/utils/__tests__/locale.test.ts
🧬 Code graph analysis (3)
packages/clerk-js/src/utils/locale.ts (1)
packages/clerk-js/src/utils/runtime.ts (1)
  • inBrowser (1-3)
packages/clerk-js/src/core/resources/SignUp.ts (1)
packages/clerk-js/src/utils/locale.ts (1)
  • getBrowserLocale (11-25)
packages/clerk-js/src/utils/__tests__/locale.test.ts (1)
packages/clerk-js/src/utils/locale.ts (1)
  • getBrowserLocale (11-25)
🔇 Additional comments (10)
playground/app-router/.gitignore (1)

28-28: LGTM!

The updated .env* pattern properly catches all environment file variants, and ignoring the /.clerk/ directory is appropriate for protecting configuration that may contain secrets.

Also applies to: 36-38

playground/app-router/README.md (1)

15-15: Verify the port change is intentional.

The port has been updated from 3000 to 4011 in the documentation. This change appears unrelated to the locale feature being added in this PR.

Is this port change intentional for the playground configuration, or was it inadvertently included?

Also applies to: 19-19

packages/types/src/signUpFuture.ts (1)

6-12: LGTM!

The optional locale field is correctly added to SignUpFutureAdditionalParams and will propagate through SignUpFutureCreateParams and SignUpFutureUpdateParams as intended.

packages/clerk-js/src/utils/index.ts (1)

26-26: LGTM!

The locale utilities are properly exported following the existing barrel export pattern.

packages/types/src/signUpCommon.ts (1)

103-103: LGTM!

The locale parameter is correctly added as an optional field to SignUpCreateParams, consistent with the existing parameter structure.

packages/types/src/signUp.ts (1)

63-63: LGTM!

The locale field is correctly added to the SignUpResource interface with the appropriate string | null type, consistent with other nullable fields like emailAddress and phoneNumber.

packages/clerk-js/src/core/resources/SignUp.ts (3)

49-49: LGTM!

The import of getBrowserLocale and the initialization of the locale property are correct.

Also applies to: 99-99


159-162: LGTM!

The browser locale is correctly injected when not explicitly provided in the create parameters.


687-689: LGTM!

The locale injection in SignUpFuture.create() correctly mirrors the implementation in the main create() method.

packages/clerk-js/src/utils/locale.ts (1)

1-25: LGTM! Clean and defensive implementation.

The function correctly handles all edge cases:

  • Returns null when not in a browser environment
  • Safely accesses navigator.language with optional chaining
  • Validates the locale is a non-empty string
  • Returns the locale in BCP 47 format when valid

The JSDoc is comprehensive, the return type is explicit, and the implementation follows TypeScript best practices.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/clerk-js/src/core/resources/SignUp.ts (1)

159-166: Locale injection logic is correct.

The implementation properly retrieves the browser locale when not explicitly provided. The getBrowserLocale() utility handles validation (non-empty string check) and returns null when unavailable, which is appropriate.

Optional: Consider unifying locale injection logic.

There's a minor difference in how locale is injected here versus in SignUpFuture.create (lines 696-698):

  • This approach: Only adds locale if browserLocale is truthy
  • SignUpFuture approach: Uses params.locale || getBrowserLocale() || undefined

Consider extracting this into a shared helper function to ensure consistent behavior across both paths:

// In utils or as a private method
const getLocaleForSignUp = (providedLocale?: string | null): string | undefined => {
  if (providedLocale) return providedLocale;
  const browserLocale = getBrowserLocale();
  return browserLocale || undefined;
};

Then use it in both places:

finalParams.locale = getLocaleForSignUp(finalParams.locale);
📜 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 c3c3ba3 and bb5bdc9.

📒 Files selected for processing (5)
  • packages/clerk-js/src/core/resources/SignUp.ts (7 hunks)
  • packages/clerk-js/src/test/core-fixtures.ts (1 hunks)
  • packages/clerk-js/src/utils/__tests__/locale.test.ts (1 hunks)
  • packages/types/src/json.ts (1 hunks)
  • packages/types/src/signUpFuture.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/types/src/signUpFuture.ts
  • packages/clerk-js/src/utils/tests/locale.test.ts
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{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/types/src/json.ts
  • packages/clerk-js/src/test/core-fixtures.ts
  • packages/clerk-js/src/core/resources/SignUp.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/types/src/json.ts
  • packages/clerk-js/src/test/core-fixtures.ts
  • packages/clerk-js/src/core/resources/SignUp.ts
packages/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/types/src/json.ts
  • packages/clerk-js/src/test/core-fixtures.ts
  • packages/clerk-js/src/core/resources/SignUp.ts
packages/**/*.{ts,tsx,d.ts}

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

Packages should export TypeScript types alongside runtime code

Files:

  • packages/types/src/json.ts
  • packages/clerk-js/src/test/core-fixtures.ts
  • packages/clerk-js/src/core/resources/SignUp.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/types/src/json.ts
  • packages/clerk-js/src/test/core-fixtures.ts
  • packages/clerk-js/src/core/resources/SignUp.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/types/src/json.ts
  • packages/clerk-js/src/test/core-fixtures.ts
  • packages/clerk-js/src/core/resources/SignUp.ts
🧬 Code graph analysis (1)
packages/clerk-js/src/core/resources/SignUp.ts (1)
packages/clerk-js/src/utils/locale.ts (1)
  • getBrowserLocale (11-25)
⏰ 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: Formatting | Dedupe | Changeset
  • GitHub Check: Build Packages
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (8)
packages/types/src/json.ts (1)

139-139: LGTM!

The addition of locale: string | null to the SignUpJSON interface is correct and aligns with the PR objectives. The nullable type maintains backwards compatibility, and the placement alongside other metadata fields is logical.

packages/clerk-js/src/test/core-fixtures.ts (1)

234-235: LGTM!

The test fixture correctly includes the new legal_accepted_at and locale fields, maintaining consistency with the updated SignUpJSON interface.

packages/clerk-js/src/core/resources/SignUp.ts (6)

49-49: LGTM!

Import of getBrowserLocale utility is appropriate for the locale injection functionality.


99-99: LGTM!

The locale property is correctly added to the SignUp class with the appropriate type.


490-490: LGTM!

Correctly populates the locale field from JSON data in the deserialization path.


519-519: LGTM!

The locale field is correctly included in the snapshot serialization, maintaining consistency with other fields.


635-637: LGTM!

The locale getter properly exposes the field through the SignUpFuture wrapper.


696-698: Locale injection works correctly.

The logic appropriately defaults to browser locale when not provided. See the earlier comment on lines 159-166 regarding optional unification of this logic.

@guilherme6191 guilherme6191 force-pushed the guilherme/user-3606-retrieve-and-send-locale-information-with-sign-ups branch from bb5bdc9 to 9dc724c Compare October 8, 2025 20:14
Copy link

pkg-pr-new bot commented Oct 8, 2025

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

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

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

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

@clerk/types

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

@clerk/upgrade

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

@clerk/vue

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

commit: b247d8a

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/clerk-js/src/utils/__tests__/locale.test.ts (1)

10-32: Consider adding edge case tests for better coverage.

The current tests cover the main scenarios well. To strengthen coverage, consider adding tests for:

  1. Whitespace-only string: The implementation checks locale.trim() === '', but there's no explicit test for strings like ' '.
  2. Non-browser environment: The implementation calls inBrowser() first, but this path isn't tested (may require mocking inBrowser()).

Example test for whitespace-only string:

it('returns null as default when navigator.language is whitespace only', () => {
  vi.stubGlobal('navigator', { language: '   ' });

  expect(getBrowserLocale()).toBeNull();
});
📜 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 bb5bdc9 and 9dc724c.

📒 Files selected for processing (6)
  • packages/clerk-js/src/core/resources/SignUp.ts (7 hunks)
  • packages/clerk-js/src/test/core-fixtures.ts (1 hunks)
  • packages/clerk-js/src/utils/__tests__/locale.test.ts (1 hunks)
  • packages/clerk-js/src/utils/locale.ts (1 hunks)
  • packages/types/src/json.ts (1 hunks)
  • packages/types/src/signUpFuture.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • packages/types/src/json.ts
  • packages/clerk-js/src/core/resources/SignUp.ts
  • packages/types/src/signUpFuture.ts
  • packages/clerk-js/src/utils/locale.ts
  • packages/clerk-js/src/test/core-fixtures.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/utils/__tests__/locale.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/utils/__tests__/locale.test.ts
packages/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/utils/__tests__/locale.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/utils/__tests__/locale.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/utils/__tests__/locale.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/utils/__tests__/locale.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/utils/__tests__/locale.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/utils/__tests__/locale.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/utils/__tests__/locale.test.ts
🧬 Code graph analysis (1)
packages/clerk-js/src/utils/__tests__/locale.test.ts (1)
packages/clerk-js/src/utils/locale.ts (1)
  • getBrowserLocale (11-25)
⏰ 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). (6)
  • GitHub Check: Build Packages
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: semgrep/ci
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (1)
packages/clerk-js/src/utils/__tests__/locale.test.ts (1)

5-8: Cleanup properly implemented.

The afterEach hook using vi.unstubAllGlobals() correctly addresses the previous review concern about restoring global state. This ensures test isolation and prevents pollution between tests.

@guilherme6191 guilherme6191 force-pushed the guilherme/user-3606-retrieve-and-send-locale-information-with-sign-ups branch from 9dc724c to 93c8d23 Compare October 8, 2025 20:40
coderabbitai[bot]

This comment was marked as resolved.

Copy link
Member

@tmilewski tmilewski left a comment

Choose a reason for hiding this comment

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

One small suggestion, just to be safe. Let's add a changeset and 🚀!

}

// Get locale from the browser
const locale = navigator?.language;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const locale = navigator?.language;
try {
const locale = navigator?.language;
} catch {
return DEFAULT_LOCALE;
}

We might as well play it safe. Not too sure about Browser Extensions, etc here.

first_name: signUpParams.first_name,
has_password: signUpParams.has_password,
last_name: signUpParams.last_name,
legal_accepted_at: signUpParams.legal_accepted_at,
Copy link
Member

Choose a reason for hiding this comment

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

good catch!

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

Successfully merging this pull request may close these issues.

3 participants