Refactor loader.js: Async init, secure storage, and dynamic i18n support#5310
Refactor loader.js: Async init, secure storage, and dynamic i18n support#5310Pankajyadav919 wants to merge 3 commits intosugarlabs:masterfrom
Conversation
|
✅ All Jest tests passed! This PR is ready to merge. |
|
❌ Some Jest tests failed. Please check the logs and fix the issues before merging. Failed Tests: |
bf657ab to
e1b0446
Compare
|
✅ All Jest tests passed! This PR is ready to merge. |
|
❌ Some Jest tests failed. Please check the logs and fix the issues before merging. Failed Tests: |
|
@vyagh can you tell why jest test fail |
There was a problem hiding this comment.
@Pankajyadav919 This PR is too large and contains structural issues that must be addressed before review:
- locales/ja.json is fully replaced without explanation.
- loader.test.js contains duplicated describe/test blocks and repeated code.
- loader.js includes duplicated requirejs.config blocks.
- APP_VERSION is hardcoded.
- Errors in main() are silently swallowed.
This change combines multiple architectural refactors and a full locale rewrite in one PR, which makes it unsafe to review or merge.
Please split this into smaller, focused PRs and resolve the structural duplication issues before resubmitting.
and also resolve merge conflicts.
Overview
This PR improves the reliability, readability, and maintainability of the application’s initialization process by refactoring js/loader.js and updating its corresponding tests in js/tests/loader.test.js.
Key improvements include modern async/await usage, safer access to browser storage, and more robust handling of dynamic translations across the UI.
Key Changes
##js/loader.js
Async/Await Refactor
##Replaced deeply nested callbacks with async/await.
initializeI18next() now returns a Promise, ensuring i18next is fully initialized before the app continues.
##Safe localStorage Access
Replaced direct property access (localStorage.languagePreference) with localStorage.getItem('languagePreference').
Added guards to verify localStorage availability, preventing crashes in restricted or sandboxed environments.
##Dynamic Translation Updates
Updated updateContent() to re-query the DOM for [data-i18n] elements on every invocation.
Ensures that UI elements added after initial load (e.g., via languagebox.js or activity.js) are translated correctly when the language changes.
##Splash Screen Localization
Encapsulated splash screen localization logic into window.loadL10nSplashScreen.
Centralizes initialization-related localization inside the loader for better cohesion and maintainability.
###js/tests/loader.test.js
##Async Flow Alignment
Updated tests to reflect the new async/await-based initialization process.
##Improved Mocking
Enhanced localStorage and i18next mocks to accurately mirror the updated implementation.
##Verification Coverage
Confirms successful initialization.
Ensures graceful error handling.
Validates dynamic DOM updates for translated elements.
###Benefits
More predictable and robust initialization flow
Improved compatibility with restricted execution environments
Correct translation of dynamically injected UI elements
Clearer, more maintainable loader logic and tests