Files
Fleetbase-Mirror-Repo/console/app/initializers/load-runtime-config.js
roncodes 5726eb974f refactor: Move runtime config and router fix to proper Ember initializers
Refactored app.js boot sequence to follow Ember conventions:

1. Created app/initializers/load-runtime-config.js
   - Loads fleetbase.config.json before application boots
   - Uses deferReadiness/advanceReadiness pattern
   - Runs before all other initializers
   - Added performance timing with debug logging

2. Created app/instance-initializers/apply-router-fix.js
   - Applies router refresh bug fix patch
   - Runs as instance-initializer (needs app instance)
   - Runs before extension loading
   - Added performance timing with debug logging

3. Refactored app/app.js
   - Removed custom ready() hook
   - Removed document.addEventListener('DOMContentLoaded')
   - Removed manual deferReadiness/boot calls
   - Now uses standard Ember boot sequence
   - Clean, minimal implementation

Benefits:
- Follows Ember conventions and best practices
- Proper initialization order guaranteed
- Performance monitoring for boot phases
- Easier to debug and maintain
- No custom boot logic needed

Boot sequence:
1. load-runtime-config initializer (runs first)
2. Other initializers (socketcluster, etc.)
3. apply-router-fix instance-initializer
4. load-extensions instance-initializer
5. Other instance-initializers
6. Application ready
2025-11-27 23:12:14 -05:00

41 lines
1.3 KiB
JavaScript

import loadRuntimeConfig from '@fleetbase/console/utils/runtime-config';
import { debug } from '@ember/debug';
/**
* Load Runtime Config Initializer
*
* Loads runtime configuration from fleetbase.config.json before the application boots.
* This must run first to ensure all config is available for other initializers.
*
* Uses `before` to ensure it runs before any other initializers.
*
* @export
* @param {Application} application
*/
export function initialize(application) {
const startTime = performance.now();
debug('[Initializer:load-runtime-config] Loading runtime configuration...');
// Defer readiness until config is loaded
application.deferReadiness();
loadRuntimeConfig()
.then(() => {
const endTime = performance.now();
debug(`[Initializer:load-runtime-config] Runtime config loaded in ${(endTime - startTime).toFixed(2)}ms`);
application.advanceReadiness();
})
.catch((error) => {
console.error('[Initializer:load-runtime-config] Failed to load runtime config:', error);
// Still advance readiness to prevent hanging
application.advanceReadiness();
});
}
export default {
name: 'load-runtime-config',
initialize,
// Run before everything else
before: 'load-socketcluster-client'
};