-
-
Notifications
You must be signed in to change notification settings - Fork 389
fix(scripts): pin the catalog generation locale so assets are reproducible #1129
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
Open
sukvvon
wants to merge
1
commit into
main
Choose a base branch
from
fix/charts-catalog-locale
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+56
−0
Open
Changes from all commits
Commits
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
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
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,54 @@ | ||
| // The catalog case components format axis labels with `toLocaleDateString(undefined, …)` | ||
| // and `toLocaleString()`, which resolve against the machine's locale. Generating the | ||
| // landing assets on a non-English machine therefore produces different SVG text — e.g. | ||
| // `10월 6일` instead of `Oct 6` — which changes the content hash and makes | ||
| // `--check` report the committed assets as stale. | ||
| // | ||
| // `@tanstack/react-charts-catalog` already pins `en-US` on every `Intl.NumberFormat` and | ||
| // `Intl.DateTimeFormat` it constructs, so the bare prototype calls are an oversight rather | ||
| // than a deliberate choice. Until that is fixed upstream, default them here so generation | ||
| // is reproducible regardless of the machine's locale. | ||
| // | ||
| // Setting `process.env.LANG` does not work: Node resolves ICU's default locale at process | ||
| // start, before any module code runs. | ||
| // | ||
| // Imported for side effects, and must be imported before the catalog case components so the | ||
| // patch is in place when they render. Call sites that pass an explicit locale keep it. | ||
|
|
||
| const GENERATION_LOCALE = 'en-US' | ||
|
|
||
| const originalToLocaleDateString = Date.prototype.toLocaleDateString | ||
| Date.prototype.toLocaleDateString = function toLocaleDateString( | ||
| locales?: Intl.LocalesArgument, | ||
| options?: Intl.DateTimeFormatOptions, | ||
| ) { | ||
| return originalToLocaleDateString.call( | ||
| this, | ||
| locales ?? GENERATION_LOCALE, | ||
| options, | ||
| ) | ||
| } | ||
|
|
||
| const originalDateToLocaleString = Date.prototype.toLocaleString | ||
| Date.prototype.toLocaleString = function toLocaleString( | ||
| locales?: Intl.LocalesArgument, | ||
| options?: Intl.DateTimeFormatOptions, | ||
| ) { | ||
| return originalDateToLocaleString.call( | ||
| this, | ||
| locales ?? GENERATION_LOCALE, | ||
| options, | ||
| ) | ||
| } | ||
|
|
||
| const originalNumberToLocaleString = Number.prototype.toLocaleString | ||
| Number.prototype.toLocaleString = function toLocaleString( | ||
| locales?: Intl.LocalesArgument, | ||
| options?: Intl.NumberFormatOptions, | ||
| ) { | ||
| return originalNumberToLocaleString.call( | ||
| this, | ||
| locales ?? GENERATION_LOCALE, | ||
| options, | ||
| ) | ||
| } | ||
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.
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: TanStack/tanstack.com
Length of output: 250
🏁 Script executed:
Repository: TanStack/tanstack.com
Length of output: 4352
Preserve explicit invalid locale values.
locales ?? GENERATION_LOCALEtreatsnullas omitted and formats it asen-US, while the native methods throw. Uselocales === undefined ? GENERATION_LOCALE : localesin all three wrappers so only omitted locale arguments receive the generation default.🤖 Prompt for AI Agents