@@ -33,8 +33,19 @@ import { ChatPanel } from "./doctor_chat.js";
3333 */
3434export class DoctorUI {
3535 constructor ( options = { } ) {
36- // Configuration from ComfyUI settings
37- this . language = options . language || 'zh_TW' ;
36+ // ═══════════════════════════════════════════════════════════════
37+ // CRITICAL: Language Fallback Configuration
38+ // ═══════════════════════════════════════════════════════════════
39+ // ⚠️ WARNING: Fallback must be 'en' (NOT 'zh_TW' or other languages)
40+ //
41+ // This fallback is used when options.language is undefined/null
42+ // MUST MATCH:
43+ // - Backend: i18n.py (_current_language = "en")
44+ // - Frontend: doctor.js (DEFAULTS.LANGUAGE = "en")
45+ //
46+ // Last Modified: 2026-01-03 (Fixed from 'zh_TW' to 'en')
47+ // ═══════════════════════════════════════════════════════════════
48+ this . language = options . language || 'en' ; // ⚠️ DO NOT CHANGE fallback
3849 this . pollInterval = options . pollInterval || 2000 ;
3950 this . autoOpenOnError = options . autoOpenOnError || false ;
4051 this . enableNotifications = options . enableNotifications || true ;
@@ -49,16 +60,41 @@ export class DoctorUI {
4960 this . lastErrorTimestamp = 0 ;
5061 this . ERROR_DEBOUNCE_MS = 1000 ; // Ignore duplicate errors within 1 second
5162
52- // UI text translations
53- // IMPORTANT: this.uiText starts as empty object {}
54- // loadUIText() is ASYNC and will populate it later
63+ // ═══════════════════════════════════════════════════════════════
64+ // CRITICAL: UI Text Loading Order
65+ // ═══════════════════════════════════════════════════════════════
66+ // ⚠️ WARNING: this.uiText MUST be loaded BEFORE createSidebar()
67+ //
68+ // Common Bug Pattern (INCORRECT):
69+ // this.uiText = {};
70+ // this.loadUIText(); // ❌ Async, doesn't wait
71+ // this.createSidebar(); // ❌ Creates UI before translations load
72+ // Result: All UI text shows "[Missing: key_name]"
73+ //
74+ // Correct Pattern (CURRENT):
75+ // this.uiText = {};
76+ // this.loadUIText().then(() => { // ✅ Wait for translations
77+ // this.createSidebar(); // ✅ Create UI after load
78+ // });
79+ //
80+ // Why This Matters:
81+ // - Sidebar uses getUIText() extensively (save_settings_btn, etc.)
82+ // - If uiText is empty {}, getUIText() returns "[Missing: ...]"
83+ // - Users see broken UI with missing translations
84+ //
85+ // Last Modified: 2026-01-03 (Fixed race condition)
86+ // ═══════════════════════════════════════════════════════════════
5587 this . uiText = { } ;
56- this . loadUIText ( ) ;
5788
5889 this . createStyles ( ) ;
59- this . createSidebar ( ) ;
6090 this . createMenuButton ( ) ;
6191
92+ // ⚠️ CRITICAL: Load UI text FIRST, then create sidebar
93+ // DO NOT move createSidebar() before loadUIText() completes!
94+ this . loadUIText ( ) . then ( ( ) => {
95+ this . createSidebar ( ) ;
96+ } ) ;
97+
6298 // Subscribe to ComfyUI execution_error events (instant, more accurate)
6399 this . subscribeToExecutionErrors ( ) ;
64100
0 commit comments