-
Notifications
You must be signed in to change notification settings - Fork 392
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
Merged
guilherme6191
merged 7 commits into
main
from
guilherme/user-3606-retrieve-and-send-locale-information-with-sign-ups
Oct 9, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7abb603
feat: Add optional locale frowm browser to signup flow
guilherme6191 9bac8f8
feat(i18n): add locale to SignUp fixtures, class, and improve testing
guilherme6191 55028fa
chore: Update missing locale in state that implements it
guilherme6191 4541abc
refactor(i18n): only add locale key if any value is present
guilherme6191 e4478a0
feat: Add try catch to be extra safe
guilherme6191 1096c51
chore: generate changeset
guilherme6191 e07029d
refactor: Move locale util down to _create for consistency
guilherme6191 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@clerk/clerk-js': minor | ||
'@clerk/clerk-react': minor | ||
'@clerk/types': minor | ||
--- | ||
|
||
Add support for sign up `locale` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -231,6 +231,8 @@ export const createSignUp = (signUpParams: Partial<SignUpJSON> = {}) => { | |
first_name: signUpParams.first_name, | ||
has_password: signUpParams.has_password, | ||
last_name: signUpParams.last_name, | ||
legal_accepted_at: signUpParams.legal_accepted_at, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch! |
||
locale: signUpParams.locale, | ||
missing_fields: signUpParams.missing_fields, | ||
object: 'sign_up', | ||
optional_fields: signUpParams.optional_fields, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { afterEach, describe, expect, it, vi } from 'vitest'; | ||
|
||
import { getBrowserLocale } from '../locale'; | ||
|
||
describe('getBrowserLocale()', () => { | ||
afterEach(() => { | ||
vi.unstubAllGlobals(); | ||
}); | ||
|
||
it('returns the browser locale when available', () => { | ||
vi.stubGlobal('navigator', { language: 'es-ES' }); | ||
|
||
expect(getBrowserLocale()).toBe('es-ES'); | ||
}); | ||
|
||
it('returns null as default when navigator.language is not available', () => { | ||
vi.stubGlobal('navigator', { language: undefined }); | ||
|
||
expect(getBrowserLocale()).toBeNull(); | ||
}); | ||
|
||
it('returns null as default when navigator.language is empty string', () => { | ||
vi.stubGlobal('navigator', { language: '' }); | ||
|
||
expect(getBrowserLocale()).toBeNull(); | ||
}); | ||
|
||
it('returns null as default when navigator object is not defined', () => { | ||
vi.stubGlobal('navigator', undefined); | ||
|
||
expect(getBrowserLocale()).toBeNull(); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { inBrowser } from '@clerk/shared/browser'; | ||
|
||
const DEFAULT_LOCALE = null; | ||
|
||
/** | ||
* Detects the user's preferred locale from the browser. | ||
* Falls back to null if locale cannot be determined. | ||
* | ||
* @returns The browser's reported locale string (typically BCP 47 format like 'en-US', 'es-ES') or null if locale cannot be determined. | ||
*/ | ||
export function getBrowserLocale(): string | null { | ||
if (!inBrowser()) { | ||
return DEFAULT_LOCALE; | ||
} | ||
|
||
try { | ||
// Get locale from the browser | ||
const locale = navigator?.language; | ||
|
||
// Validate that we got a non-empty string | ||
if (!locale || typeof locale !== 'string' || locale.trim() === '') { | ||
return DEFAULT_LOCALE; | ||
} | ||
return locale; | ||
} catch { | ||
return DEFAULT_LOCALE; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
🛠️ Refactor suggestion | 🟠 Major
🧩 Analysis chain
Locale injection in
_create
is correct.The nullish coalescing operator properly handles the fallback: user-provided locale takes precedence, then browser locale, and finally
null
(when browser detection fails).However, ensure that the
password
,sendPhoneCode
(when!id
), andsso
methods also inject locale into their request bodies to maintain consistency across all sign-up creation flows. Previous review comments flagged this gap.🏁 Script executed:
Length of output: 0
🏁 Script executed:
Length of output: 4285
Inject locale into sendPhoneCode and SSO flows
sendPhoneCode’s initial POST (when !id) and its prepare-verification branch, as well as the SSO prepare POST, currently omit
locale: params.locale ?? getBrowserLocale()
. Add this fallback to their request bodies.🤖 Prompt for AI Agents
✅ Addressed in commits 65b7cc7 to e07029d
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.
I don't think we need that now especially because that's for the FutureSignUp logic with signal. That's experimental and I'm unsure we need to add more surface and update it now.
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.
@guilherme6191, understood! That makes sense—since
SignUpFuture
is experimental, it's reasonable to keep the scope focused for now and avoid expanding the surface area unnecessarily. The current implementation in_create
covers the main use case. 👍