Skip to content

chore: Allow dynamic deferred loading of internationalization#4237

Draft
avinashbot wants to merge 1 commit intomainfrom
feat/remote-provider-poc
Draft

chore: Allow dynamic deferred loading of internationalization#4237
avinashbot wants to merge 1 commit intomainfrom
feat/remote-provider-poc

Conversation

@avinashbot
Copy link
Member

@avinashbot avinashbot commented Feb 10, 2026

Description

Partial implementation of dynamically loaded internationalization. This lets us more readily embed the I18nProvider into performance-sensitive parts of the code (like the app layout toolbar) without worrying so much about added bundle size of the intl library, intl-messageformat (34.3 kB, 9.83 kB gzip) and the locale files (465kB, 68kB gzip). This also avoids dealing with any additional build-time considerations (intl-messageformat raises our bare minimum TypeScript version requirement, which we don't document publicly, though we do call out the raised minimum in our documentation).

The added cost is one asynchronously triggered full-application rerender.

components/LocalI18nProvider  <- The application may provide this already (this is fine)
↳ components/AppLayout
  ↳ components/AppLayout/skeleton
    ↳ components/RemoteI18nProvider <-------+
      ↳ application code                    | 
      ↳ widgetized/AppLayout/toolbar        | --- Once messages and formatter are loaded,
      ↳ widgetized/AppLayout/drawers        |     the content is re-rendered.
    ↳ widgetized/loadRemoteI18nMessages() --+

"Dynamic loading" of the internationalization bundle isn't all that complicated, it's just a runtime import of I18nFormatter (which this PR refactors out) preloaded with the appropriate locale file (which are already exposed under /messages/all.<locale>.js).


Possible optimizations (either later in this PR or after release):

  • Wrapping the app rerender in a React transition: For React versions that support it, it avoids our rerender from blocking user actions and affecting web vitals.
  • Removing ICU parser from the remote bundle (reference): If we can safely guarantee that the remote provider only accepts and handles pre-parsed AST-only strings, we can remove the parser from the dynamically loaded bundle and reduce the dynamic bundle's file size by 26.34 kB (7.1 kB gzip). But this is a non-blocking network request, so it's not high priority. See CR-253557644.

Related links, issue #, if available: AWSUI-61508

How has this been tested?

Existing tests for locally (i.e. application) provided strings, additional tests for remote inclusion of logic will follow.

Review checklist

The following items are to be evaluated by the author(s) and the reviewer(s).

Correctness

  • Changes include appropriate documentation updates.
  • Changes are backward-compatible if not indicated, see CONTRIBUTING.md.
  • Changes do not include unsupported browser features, see CONTRIBUTING.md.
  • Changes were manually tested for accessibility, see accessibility guidelines.

Security

Testing

  • Changes are covered with new/existing unit tests?
  • Changes are covered with new/existing integration tests?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov
Copy link

codecov bot commented Feb 10, 2026

Codecov Report

❌ Patch coverage is 97.87234% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.18%. Comparing base (9fc78ce) to head (a270b41).

Files with missing lines Patch % Lines
src/i18n/providers/remote-provider.tsx 90.47% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4237      +/-   ##
==========================================
- Coverage   97.19%   97.18%   -0.01%     
==========================================
  Files         886      889       +3     
  Lines       26021    26049      +28     
  Branches     9433     9438       +5     
==========================================
+ Hits        25291    25317      +26     
+ Misses        724      685      -39     
- Partials        6       47      +41     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant