Repository navigation
fix(web): write numbers and dates in en-US whatever the browser's locale, and lint against locale-less calls - #1549
Merged
Conversation
…ale, and lint against locale-less calls Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
approved these changes
Oct 26, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Looks good, with a follow-up.
What I checked:
- Numbers. Every
toLocaleString()the PR turns intoformatNumbergives the same text for an English browser:formatNumberistoLocaleString('en-US')with no options, so the grouping and the default of up to 3 decimals don't change. The calls that keep their own options change onlyundefinedto'en-US': Shopping's dates, times and prices,formatPriceinlib/actions/shopping.ts, and Competitors' dates. Under en-US their output is the same, includinghour: '2-digit'and the 2-decimal prices. - Dates.
formatDateandformatDateTime(lib/format.ts) take notimeZone, so they read the browser's zone as the old calls did, and no day moves. For an English browser, five lines change:- Improve tab "Generated" (
prompt-improve-tab.tsx:383) and the Insights result's "Checked" (insights/[id]/page.tsx:213): "10/17/2026, 2:05:33 PM" becomes "Oct 17, 2026, 2:05 PM". The seconds go too; the PR body mentions only the month. - Improve tab "Sent" (
:389), the basket's "Measured from" (opportunity-basket.tsx:395) and Team's "Expires" (team-section.tsx:385): "10/17/2026" becomes "Oct 17, 2026". - These match the format the rest of the app uses. In the basket, a bad date now reads "—" where it read "Invalid Date". The guard is needed because
toISOString()throws on an invalid date.
- Improve tab "Generated" (
- Server and client. Every file it touches is a client component whose values arrive after mount (effects or the Improve controller).
formatPriceruns in a server action and returns plain data. Nothing new is rendered on the server, so no hydration mismatch is added. - The lint rule. I ran its seven selectors, read from the PR's
eslint.config.mjs, over a probe and overweb/srcafter merging main.- It flags each locale-less form:
toLocaleString(),toLocaleDateString()andtoLocaleTimeString()(also with?.), the same calls withundefinedor[], andIntlformatters built with no locale, withundefinedor with[], with or withoutnew. - It leaves alone calls with
'en-US', alocalevariable,localeCompare,toLocaleLowerCase,Intl.supportedValuesOf('timeZone')andnew Intl.Segmenter('en', …). - On the merged tree it finds nothing in 738 source files. The only matches are the two in
lib/format.test.ts, which simulate a Turkish browser on purpose, and the config skips tests.
- It flags each locale-less form:
- Missed spots: none. Each
toLocale*StringandIntl.*call left inweb/srcnames'en-US'/'en', or alocalefrom next-intl'suseLocale(), passed directly or throughnumberFormat,dayLabelorsuggestedDate. The one exception islib/time-zone.ts'sIntl.DateTimeFormat().resolvedOptions(). next-intl'suseFormatterfollows the UI's locale too. - Test. The new Improve tab case makes
Date's locale methods default totr-TRand checks the text on screen ("Generated Oct D, 2026, H:MM AM/PM" and "Sent Oct D, 2026 · AC-12"). It fails on the old code. The regexes allow any zone from −12 to +14, and\saccepts the narrow no-break space newer ICU puts before AM/PM. The existing budget tests are unchanged, andrestoreAllMocksinafterEachputs the prototypes back. - Merge. Main has gained only #1547 (server) since the PR's base. The PR merges cleanly on c58edb8, and the merged
web/tree is the PR's own, so the lint, typecheck and format CI passes at 7cf8b8d stand. None of the open PRs adds a locale-less call, so merging this first doesn't break their lint. - Before the API deploy. Web only, with no API dependency. English browsers see the five dates above in the new format, and other browsers see numbers and dates in en-US. No live feature changes.
Follow-up:
-
The rule's zero-argument
Intlcase (web/eslint.config.mjs:38,:43). The comment saysIntl.DateTimeFormat()alone is allowed for reading the time zone, but:new Intl.DateTimeFormat().resolvedOptions().timeZone, a common form of the same read, is flagged;Intl.DateTimeFormat().format(date)is not flagged, though it formats in the browser's locale.
One selector in place of the two fixes both. I checked it: it allows only a zero-argument formatter whose
resolvedOptions()is read, and it still passeslib/time-zone.ts.{ selector: ":matches(NewExpression, CallExpression)[callee.object.name='Intl'][arguments.length=0]:not(MemberExpression[property.name='resolvedOptions'] > .object)", message: "Name the locale: pass 'en-US'.", },
7 of 12 tasks
5 of 12 tasks
gkhngyk
pushed a commit
that referenced
this pull request
Oct 26, 2026
…vedOptions, with or without new (#1549 review) (#1555) Co-authored-by: Cihan <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
The UI is English-only, but some numbers and dates still followed the browser's locale. A Turkish browser showed 1,232 as "1.232" and dates as "17.10.2026". #1095 added
formatNumber(en-US) and converted the Prompts page. This converts the rest ofweb/srcand adds a lint rule so locale-less calls can't come back.Numbers →
formatNumber(the same output for an English browser):Calls that set their own options keep them, with
'en-US'in place ofundefined:lib/actions/shopping.ts);Dates with no options → the helpers the rest of the app uses:
formatDate: "Oct 17, 2026";formatDateTime: "Oct 17, 2026, 2:05 PM".They're used for:
For an English browser these few dates change from "10/17/2026" to "Oct 17, 2026". Both are still read in the browser's time zone, as before. A bad date in the basket shows "—" rather than throwing.
Lint (
web/eslint.config.mjs,no-restricted-syntax;src/, tests excluded) flags:toLocaleString()/toLocaleDateString()/toLocaleTimeString()with no locale,undefinedor[];Intlformatter built without one (new Intl.NumberFormat(),Intl.NumberFormat(undefined, …),new Intl.Collator([])…).Intl.DateTimeFormat()alone stays allowed:lib/time-zone.tsreads the browser's time zone with it. I checked the rule on a probe file: it flagged the 9 locale-less forms and passed the 4 correct ones. Nothing insrc/breaks it after this change.Related issue
Follow-up to #1095 (no issue).
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/): 0 errors; the 6 warnings were already on mainyarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Also run:
yarn test(427 files, 4,055 tests) andyarn build.Test: the Improve tab renders with
Date's locale methods defaulting totr-TRand shows English dates. It fails without the fix and passes in UTC, Asia/Kolkata and Pacific/Auckland. The day and time aren't pinned, since they follow the zone the tests run in.Pre-push review
A review agent read the change before the push. It found no missed call sites in
web/src. Fixed from it:afterEach;[], calls withoutnew, and otherIntlconstructors.Left out of scope: the reviewer noted that a few client-side sorts use
localeComparewithout a locale. In a Turkish browser they could order labels starting with "I" differently. That's a rare case and not a formatting issue.🤖 Generated with Claude Code