-
Notifications
You must be signed in to change notification settings - Fork 391
feat(clerk-js, types): Add optional locale
from browser to signup flow
#6915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(clerk-js, types): Add optional locale
from browser to signup flow
#6915
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughAdds browser-derived locale propagation to sign-up flows: new getBrowserLocale utility and tests, locale fields added to types and SignUp/SignUpFuture classes, locale serialized in JSON and fixtures, and minor playground .gitignore/README updates. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant UI as App UI
participant SU as SignUp client
participant Util as getBrowserLocale()
participant API as Backend API
User->>UI: Submit sign-up (params may omit locale)
UI->>SU: SignUp.create(params)
alt params.locale provided
SU->>API: POST /sign-ups { ..., locale }
else params.locale missing
SU->>Util: getBrowserLocale()
Util-->>SU: locale \| null
SU->>API: POST /sign-ups { ..., locale? }
end
API-->>SU: 201 Created { locale }
SU-->>UI: SignUpResource { locale }
UI-->>User: Show sign-up result
sequenceDiagram
autonumber
actor User
participant UI as App UI
participant SUF as SignUpFuture client
participant Util as getBrowserLocale()
participant API as Backend API
User->>UI: Start future sign-up
UI->>SUF: SignUpFuture.create(params?)
alt params.locale missing
SUF->>Util: getBrowserLocale()
Util-->>SUF: locale \| null
end
SUF->>API: POST /sign-ups { ..., locale? }
API-->>SUF: 201 Created
SUF-->>UI: Future result with locale
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good, but holding off on approving as we'll need to get the supporting work in.
5f02d05
to
1cf759a
Compare
locale
from browser to signup flow
1cf759a
to
c3c3ba3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 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 populatethis.locale
from the API response data. This means the locale value will be lost when theSignUp
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 thelocale
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.
📒 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
Avoidany
type - preferunknown
when type is uncertain, then narrow with type guards
Useinterface
for object shapes that might be extended
Usetype
for unions, primitives, and computed types
Preferreadonly
properties for immutable data structures
Useprivate
for internal implementation details
Useprotected
for inheritance hierarchies
Usepublic
explicitly for clarity in public APIs
Preferreadonly
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
Useconst assertions
for literal types:as const
Usesatisfies
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 ...
Noany
types without justification
Proper error handling with typed errors
Consistent use ofreadonly
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 toSignUpFutureAdditionalParams
and will propagate throughSignUpFutureCreateParams
andSignUpFutureUpdateParams
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 toSignUpCreateParams
, consistent with the existing parameter structure.packages/types/src/signUp.ts (1)
63-63
: LGTM!The
locale
field is correctly added to theSignUpResource
interface with the appropriatestring | null
type, consistent with other nullable fields likeemailAddress
andphoneNumber
.packages/clerk-js/src/core/resources/SignUp.ts (3)
49-49
: LGTM!The import of
getBrowserLocale
and the initialization of thelocale
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 maincreate()
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (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 returnsnull
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.
📒 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
Avoidany
type - preferunknown
when type is uncertain, then narrow with type guards
Useinterface
for object shapes that might be extended
Usetype
for unions, primitives, and computed types
Preferreadonly
properties for immutable data structures
Useprivate
for internal implementation details
Useprotected
for inheritance hierarchies
Usepublic
explicitly for clarity in public APIs
Preferreadonly
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
Useconst assertions
for literal types:as const
Usesatisfies
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 ...
Noany
types without justification
Proper error handling with typed errors
Consistent use ofreadonly
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 theSignUpJSON
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
andlocale
fields, maintaining consistency with the updatedSignUpJSON
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 theSignUp
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.
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 tonull
.Related PRs for extra context, if needed:
Note: this shouldn't error out in Expo, 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
Summary by CodeRabbit