This repository was archived by the owner on Nov 4, 2026. It is now read-only.
Repository navigation
refactor(fields): the currency adornment's symbol has one channel (#4414) - #4427
Merged
Merged
Conversation
) `CurrencyField` carried the same one-entry fact twice: a dead `CURRENCY_SYMBOLS` map that nothing read (eslint had been reporting it as an unused-var WARNING, which the lint gate does not fail on), and a live `currency === 'USD' ? '$' : currency` ternary two lines below it. Measured per the ruling: both are hand copies of knowledge `Intl` already carries, and the derivation fits. `currencySymbol(currency, locale)` lands beside `currencyFractionDigits()` and reads the `currency` part of the SAME `Intl.NumberFormat` the readonly branch already formats amounts through, so the widget's two modes can no longer disagree — they did: `JPY` in the edit adornment beside a readonly `¥1,235`. Unlike the digit count, the symbol is NOT locale-independent (USD is `$` at en/en-US/de-DE/ja-JP, `US$` at en-GB/zh-CN, `$US` at fr-FR), so the helper takes the display locale as a parameter and caches on the PAIR. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017Qqyix2QcnpUC9XeYVDzx3
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
✅ Console Performance Budget
📦 Bundle Size Report
Size Limits
|
Contributor
Author
|
ACCEPT — PM 复核 (session
Flipping ready + arming auto-merge. Generated by Claude Code |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fixes #4414
CurrencyField.tsxcarried the same one-entry fact twice: a deadCURRENCY_SYMBOLSmap that nothing read, and a livecurrency === 'USD' ? '$' : currencyternary two lines below it. The PM ruling on the card says one channel survives, and thatIntlis the candidate to measure first. It was measured, it fits, and both hand copies are gone.The Intl-fit measurement
Intl.NumberFormat(locale, { style: 'currency', currency }).formatToParts()has acurrencypart. Measured on node 22 / full-ICU, against what the ternary produces today:currencypart (en)$$EUR€JPYGBP£INR₹KRW₩The ruling anticipated that ICU may answer with the CODE for some pairs (KWD was the example) and asked whether that is right for an adornment. Measured: it is, and it is also what the ternary already did for exactly those currencies — so that row of the table is byte-identical rather than a compromise.
The decisive finding is not the table, though. It is that the readonly branch of this same widget already renders the Intl-derived symbol, because it formats through
formatDisplayNumber(value, { locale, currency })— the very sameIntlcall. So the widget contradicted itself: atena JPY field rendered¥1,235in readonly mode andJPYin the edit adornment beside it. The new helper reads one part of the format the widget was already using, so the two modes cannot disagree again.The one channel
currencySymbol(currency, locale)lands inpackages/fields/src/currency.tsbesidecurrencyFractionDigits(), same memoization shape. Deleted: theCURRENCY_SYMBOLSmap and the ternary. Exactly one spelling remains, and a repo-wide grep finds no other hand-restatement of the symbol.It takes the display locale as a parameter, and that is a measured divergence from its sibling.
currencyFractionDigits()drops the locale because the digit count is locale-independent. The symbol is not:$aten/en-US/de-DE/ja-JP,US$aten-GB/zh-CN,$USatfr-FRen, the fullwidth U+FFE5 atja-JP,JP¥aten-GB, and the bare codeJPYatfr-FRSo the cache is keyed on the (locale, currency) pair. Copying the code-only cache key would have let whichever locale asked first answer for every locale after it, for the life of the process — a silent wrong answer rather than a crash, so there is a test pinning it directly.
Both
Intlthrows are caught and fall back to the code as given:RangeError: Invalid currency code, andRangeError: Incorrect locale information provided(whichcurrencyFractionDigitsdodged by dropping the locale — this helper needs it, so it catches). This runs during render; an escapedRangeErrorwould be a blank widget.USD byte-identical, and the non-USD change stated
USD is byte-identical at the display-locale default.
useDisplayLocale()'s own last resort is'en', andcurrencySymbol('USD', 'en')is$— the same byte the ternary produced. Pinned at'en', at'en-US', and through the ADR-0053 tenant default. The reverse verification below is the proof: reverting the wiring leaves every USD pin green.The documented change is non-USD, and it is a deliberate choice rather than a side effect: a currency CLDR has a symbol for now renders that symbol instead of its three-letter code. This is the shortcoming the issue itself flagged as possibly worth fixing ("a widget that shows
KWDrather than a symbol for every non-USD currency is arguably its own shortcoming"), and it aligns the edit adornment with what this widget's readonly mode has displayed all along. One pre-existing test asserted the old output (standard-widgets.test.tsx, "should handle EUR currency",getByText('EUR')); it pinned exactly the limb being deleted, so it is re-judged to€with a comment recording why.Layout is unaffected: the adornment is an absolutely-positioned prefix span with the input padded by
pl-8, and every new string is 1-3 characters — the same width class as the codes it replaces. Pinned thatpl-8is still applied with a currency and still absent without one.Verification
pnpm exec vitest run packages/fields/ --maxWorkers=2(repo root) — 83 files, 1325 tests, all passed.CurrencyField.minorUnits.test.tsx— 16 passed, run both in the full pass and targeted. It asserts digit counts andstep, never the adornment, so it is untouched in both directions.tsc --noEmitandtsc(declaration build) forpackages/fields— both exit 0. Dependency closure built first (pnpm --filter '@object-ui/fields^...' build).check:control-bytesOK (4128 files),check:phantom-depsOK,check:changeset-presence/changeset-fixed/changeset-no-majorOK. Changeset is a patch.origin/main:CurrencyField.tsxgoes 3 warnings to 2, and the one that disappears is exactly the card's bonus signal —'CURRENCY_SYMBOLS' is assigned a value but never used [@typescript-eslint/no-unused-vars]. The new test file adds 1no-explicit-any(the single unavoidable field-metadata cast, matching the sibling test's convention), so the package total is 757 to 757 — net zero, 0 errors throughout.Red-first
The pins were written and run before the source changed: 13 failed / 15 passed. The reds were the 5 non-USD symbol pins (
expected 'EUR' to be '€'), the 3 self-agreement pins (expected '¥1,235' to contain 'JPY'— the contradiction, caught in the act), and the 5 helper unit pins. The 15 that passed pre-change are the controls: every USD pin, the no-currency and padding pins, and the code-only currencies.Reverse verification
Committed, then reverted only the wiring line (helper and tests left in place), with the direction predicted in writing first. Predicted 9 red and named them; got exactly those 9, with the predicted messages:
The controls stayed green, and that is the load-bearing half:
currencySymbol()unit pins — a wiring revert cannot reach the helper's own behaviour, so predicting "revert, therefore everything red" would have been wrong here. Naming the direction first is what makes the run mean something.Wiring restored afterwards; the tree matches the commit.
Generated by Claude Code