Repository navigation
perf(i18n): lazy load active locale bundles with shared cache and atomic transitions - #398
Merged
Merged
Conversation
… transitions (#375) Replaces the eager static message imports with on-demand locale chunks: - frontend/src/lib/i18n/loader.ts (new): shared loader with a message cache (English primed synchronously as the packaged cold-boot fallback) and in-flight promise deduplication for React and non-React consumers. - languages.ts: registry now only declares dynamic chunk loaders; the four message JSON files are no longer statically imported into the main graph. - I18nProvider: resolves the initial language deterministically (persisted store preference -> browser match against selectable languages -> English), loads locale bundles asynchronously with stale-load protection (latest request wins), applies the switch atomically, and reverts the store request on failure so the current language keeps rendering. - t() adapter reads from the shared loader cache (target -> English -> raw key fallback unchanged); English renders until the active chunk arrives, so no raw-key flashing is possible. - HtmlLangSync / KdsHtmlLang apply <html lang>/<html dir> only after the locale has loaded (atomic direction transition, no flip ahead of messages) and use getLanguageLocale() instead of hard-coded tags. - tests/locale-chunk-splitting.test.ts (new, wired into npm test): asserts es/pt/fa ship as independent lazy chunks that no page eagerly references, with no external network references (offline invariant). Measured bundle impact (before -> after, static export): - Before: every page eagerly loaded all 4 locale chunks (en 95 KB + es 108 KB + pt 107 KB + fa 143 KB = 453 KB). - After: only packaged English (95 KB) is eager; es/pt/fa (~357 KB) are fetched only when their locale activates.
This was referenced Aug 19, 2026
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Intent
Implement issue #375 of the FloCafe i18n epic (#372): lazy-load the active locale translation bundle so only the active locale is fetched at startup, with a shared loader/cache (loader.ts), race-safe atomic language switching in I18nProvider (latest request wins, revert on failure), packaged-English cold-boot fallback, atomic html lang/dir transitions, and measured before/after bundle verification for the static export. Keep the legacy t() adapter and existing consumers working; do not migrate components to use-intl hooks (reserved for issues #376-380). Also remove the orphaned no-mistakes evidence test file that was accidentally merged with #396.
What Changed
loader.ts) that synchronously provides packaged English as a cold-boot fallback and fetches non-English locales on demand.I18nProvider,HtmlLangSync,KdsHtmlLang, andSetupPageto load bundles asynchronously with race guards (latest request wins, store revert on failure) and atomic HTMLlang/dirdocument synchronization.tests/locale-chunk-splitting.test.tsto verify static export chunk code-splitting and asset locality in CI, and removed the orphaned test file from#396.Risk Assessment
✅ Low: The change cleanly implements lazy locale chunk loading with robust promise deduplication, synchronous English cold-boot fallback, race-safe atomic language switching, and comprehensive static export chunk verification.
Testing
Exercised the static frontend export build, chunk splitting validation, translation and RTL suites, in-memory loader/cache logic, and Playwright end-to-end browser flows across English, Spanish, Portuguese, and Persian; all 37 localized tests, RTL suites, and code-split assertions passed with 7 visual and report artifacts produced.
Evidence: Static Export Lazy Locale & Bundle Splitting Report
/var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/no-mistakes-evidence/01M0BXGFQ9Q4KZ4C72Q5NAB5XX/01_setup_english_cold_boot.png) - Evidence: Setup Screen — Spanish (Lazy chunk 1aavjbtshc_zk.js fetched on-demand) (local file:/var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/no-mistakes-evidence/01M0BXGFQ9Q4KZ4C72Q5NAB5XX/02_setup_spanish_lazy_loaded.png) - Evidence: Setup Screen — Portuguese (Lazy chunk 06niv83zaxzfj.js fetched on-demand) (local file:/var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/no-mistakes-evidence/01M0BXGFQ9Q4KZ4C72Q5NAB5XX/03_setup_portuguese_lazy_loaded.png) - Evidence: Login Screen — English Baseline (lang='en', dir='ltr') (local file:/var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/no-mistakes-evidence/01M0BXGFQ9Q4KZ4C72Q5NAB5XX/04_login_english_baseline.png) - Evidence: Login Screen — Spanish (Atomic lang='es', dir='ltr' sync) (local file:/var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/no-mistakes-evidence/01M0BXGFQ9Q4KZ4C72Q5NAB5XX/05_login_spanish_atomic_sync.png) - Evidence: Login Screen — Persian RTL (Atomic lang='fa-IR', dir='rtl' sync with lazy chunk 05h-hgoy6fn1u.js) (local file:/var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/no-mistakes-evidence/01M0BXGFQ9Q4KZ4C72Q5NAB5XX/06_login_persian_rtl_atomic_sync.png)Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
npm run build:frontendnpm run test:locale-chunksnpm run test:translationsnpm run test:rtl-foundationnpm run test:rtl-setup-auth-settingsnpm run test:rtl-dashboard-pos-commonnpm run test:rtl-kds-server-whatsappnode tests/run-electron-node-test.cjs tests/issue-241-localized-errors.test.tsnode tests/run-electron-node-test.cjs tests/browser-receipts.test.tsE2E Playwright verification on static export (/setup, /auth/login) exercising cold-boot English fallback, on-demand chunk fetching for Spanish, Portuguese, and Persian, and atomic lang/dir synchronizationUnit test verification of loader.ts cache priming, promise deduplication, and legacy t() nested resolution✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.