-
Notifications
You must be signed in to change notification settings - Fork 5k
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
fix: Intl.NumberFormat locale RangeError related to Simulation Details #24068
Conversation
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
6592878
to
ca65bb1
Compare
ca65bb1
to
56b2b72
Compare
ui/ducks/locale/locale.js
Outdated
* @returns {string} one of the codes in file://./../../../app/_locales/index.json. | ||
* These codes are not safe to use with the Intl API. | ||
*/ | ||
export const getLocaleNotSafeForIntl = (state) => |
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.
For the sake of minimising refactor and the PR diff, is this really needed if SimulationDetails
was the first usage of Intl.NumberFormat
with one of these locales, and there was no issues previously?
Would the above warning in the JSDoc, plus the presence of the getIntlLocale
method be a sufficient deterrent?
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.
Done.
ui/ducks/locale/locale.js
Outdated
export const getCurrentLocale = (state) => state.localeMessages.currentLocale; | ||
/** | ||
* @param state | ||
* @returns {string} one of the codes in file://./../../../app/_locales/index.json. |
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.
Should we be explicit in both these method's JSDoc that it's the user's selected locale that is returned?
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.
Done.
ui/ducks/locale/locale.test.ts
Outdated
}); | ||
|
||
describe('getIntlLocale', () => { | ||
it.each(locales)('can convert locale "%s" to BCP 47 format', (locale) => { |
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.
Love this test! But if this is the happy path, should we also have a unit test to verify we throw if a bad locale is in the state?
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.
Good call. Done.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #24068 +/- ##
===========================================
+ Coverage 67.56% 67.58% +0.02%
===========================================
Files 1246 1247 +1
Lines 48888 48938 +50
Branches 12746 12775 +29
===========================================
+ Hits 33031 33073 +42
- Misses 15857 15865 +8 ☔ View full report in Codecov by Sentry. |
Description
Problem: The locale returned by
getCurrentLocale
is not meant to be used with the Intl API.To fix this, this PR will:
getCurrentLocale
=>getLocaleNotSafeForIntl
to alert developers in the future.getIntlLocale
which converts the locale returned fromgetLocaleNotSafeForIntl
into a BCP 47 Language Tag which can be used with the Intl API.getIntlLocale
works with all our locales going forward.Related issues
Fixes: #24067
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist