[number field] Fix formatter locale cache#4999
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,078.42 ms ▼-407.79 ms(-27.4%) | Renders: 50 (+0) | Paint: 1,638.75 ms ▼-598.87 ms(-26.8%)
…and 7 more — details Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Code Review (GPT-5.5)Approve ✅ The formatter cache key now preserves 1. Bugs / Issues (None)I didn’t find any blocking or non-blocking issues in the full branch diff against freshly fetched 2. Root Cause & Patch AssessmentThe fix targets the actual collision: 3. Test Coverage AssessmentThe new regression test covers the reported Validation run: All passed, and GitHub checks for the PR head are green. |
d974bb4 to
f369783
Compare
There was a problem hiding this comment.
Pull request overview
Fixes an Intl.NumberFormat cache-key bug where Intl.Locale inputs were serialized as {} by JSON.stringify, causing formatter reuse across different locales when options matched.
Changes:
- Introduced a
stringifyLocale()utility to normalizeIntl.LocalesArgumentinto a stable string for cache keys. - Updated
getFormatter()to use the stringified locale when building the formatter cache key. - Added regression tests covering distinct
Intl.Localeobjects for both number formatting and collator-based filtering caches.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/react/src/utils/stringifyLocale.ts | Adds a locale stringifier helper for stable cache keys. |
| packages/react/src/utils/stringifyLocale.test.ts | Adds unit coverage for stringifyLocale() across supported locale argument shapes. |
| packages/react/src/utils/formatNumber.ts | Fixes number formatter cache-key generation by stringifying locale inputs. |
| packages/react/src/utils/formatNumber.test.ts | Adds regression coverage ensuring different Intl.Locale objects don’t share cached number formatters. |
| packages/react/src/internals/filter.ts | Reuses the shared stringifyLocale() helper instead of duplicating logic. |
| packages/react/src/internals/filter.test.ts | Adds regression coverage ensuring different Intl.Locale objects don’t share cached filters. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Intl.Localeobjects could reuse the wrong cached number formatter when two locales used the same formatting options.Root cause
Intl.Localeinstances serialize to{}withJSON.stringify, so the locale part of the formatter cache key was lost.Changes
Intl.Localeobjects with the same options.