-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
perf: ensure setupLocale
doesn't fetch _locales/en/messages.json
twice
#26553
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. |
3e3be88
to
76c903e
Compare
Builds ready [76c903e]
Page Load Metrics (87 ± 22 ms)
Bundle size diffs
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #26553 +/- ##
===========================================
+ Coverage 69.96% 70.01% +0.05%
===========================================
Files 1405 1405
Lines 48996 49049 +53
Branches 13697 13714 +17
===========================================
+ Hits 34280 34341 +61
+ Misses 14716 14708 -8 ☔ View full report in Codecov by Sentry. |
76c903e
to
ba6741c
Compare
Quality Gate passedIssues Measures |
const enRelativeTime = loadRelativeTimeFormatLocaleData(defaultLocale); | ||
const enLocale = fetchLocale(defaultLocale); | ||
|
||
await loadRelativeTimeFormatLocaleData('en'); | ||
if (currentLocale) { | ||
await loadRelativeTimeFormatLocaleData(currentLocale); | ||
const promises = [enRelativeTime, enLocale]; | ||
if (currentLocale === defaultLocale) { | ||
// enLocaleMessages and currentLocaleMessages are the same; reuse enLocale | ||
promises.push(enLocale); // currentLocaleMessages | ||
} else if (currentLocale) { | ||
// currentLocale does not match enLocaleMessages | ||
promises.push(fetchLocale(currentLocale)); // currentLocaleMessages | ||
promises.push(loadRelativeTimeFormatLocaleData(currentLocale)); | ||
} else { | ||
// currentLocale is not set | ||
promises.push(Promise.resolve({})); // currentLocaleMessages | ||
} | ||
|
||
const [, enLocaleMessages, currentLocaleMessages] = await Promise.all( | ||
promises, | ||
); |
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.
This is really two changes:
- don't fetch the
"en"
locale twice - if we have to fetch multiple locales, do them at the same time.
Builds ready [ba6741c]
Page Load Metrics (75 ± 6 ms)
Bundle size diffs
|
Builds ready [5982850]
Page Load Metrics (1993 ± 128 ms)
Bundle size diffs
|
5982850
to
7602777
Compare
7602777
to
5a18b3a
Compare
Quality Gate passedIssues Measures |
Builds ready [5a18b3a]
Page Load Metrics (2047 ± 57 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [b49a9a4]
Page Load Metrics (1931 ± 104 ms)
Bundle size diffs
|
We always load the english version of
messages.json
, but we also always load the user's locale'smessages.json
. These can be the same thing but our locale loader didn't take that into consideration. This PR updates the function to only load the user's local if it differs from our default locale, otherwise it just uses the samemessages.json
between the two.Our locale function has a side effect: it loads locale-related Internationalization features as well. So this PR also updates those side-effects in a similar manner to avoid doing the work twice.