Skip to content

Refactor loader.js: Async init, secure storage, and dynamic i18n support#5310

Closed
Pankajyadav919 wants to merge 3 commits intosugarlabs:masterfrom
Pankajyadav919:fix/loader-initialization
Closed

Refactor loader.js: Async init, secure storage, and dynamic i18n support#5310
Pankajyadav919 wants to merge 3 commits intosugarlabs:masterfrom
Pankajyadav919:fix/loader-initialization

Conversation

@Pankajyadav919
Copy link
Contributor

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

@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@github-actions
Copy link
Contributor

❌ Some Jest tests failed. Please check the logs and fix the issues before merging.

Failed Tests:

loader.test.js

@Pankajyadav919 Pankajyadav919 force-pushed the fix/loader-initialization branch from bf657ab to e1b0446 Compare January 24, 2026 15:56
@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@github-actions
Copy link
Contributor

❌ Some Jest tests failed. Please check the logs and fix the issues before merging.

Failed Tests:

loader.test.js

@Pankajyadav919
Copy link
Contributor Author

@vyagh can you tell why jest test fail

Copy link
Contributor

@vanshika2720 vanshika2720 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

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.

2 participants