Fix dark mode: purge stale theme=light from DB on startup

The previous fix changed code defaults to dark but the DB still had
theme='light' stored explicitly — a truthy value that bypassed all
fallbacks. On every restart the server was returning theme:'light',
which the client applied via data-theme="light", making the app white.

- Delete the 'theme' key from DB on startup (one-time migration)
- Always return theme:'dark' from buildSettingsFromDb (not from DB)
- Stop writing theme to DB/env/process.env on settings save

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
nmemmertandClaude Sonnet 4.6 committed 2026-08-06 13:04:52 -04:00
1 parent 50f4f73af1
commit de4619992e
1 file changed
+10 -4
+10 -4
View File
@@ -39,6 +39,12 @@ try {
console.error('Error initializing notifications table:', error); console.error('Error initializing notifications table:', error);
} }
// One-time: remove stale theme setting from DB (app is always dark mode)
try {
db.prepare("DELETE FROM settings WHERE key = 'theme'").run();
} catch (_) {}
const app = express(); const app = express();
const PORT = process.env.PORT || 3001; const PORT = process.env.PORT || 3001;
@@ -135,7 +141,7 @@ function buildSettingsFromDb(dbSettings = {}) {
default_sort: dbSettings.default_sort || process.env.DEFAULT_SORT || 'name', default_sort: dbSettings.default_sort || process.env.DEFAULT_SORT || 'name',
items_per_page: parseInt(dbSettings.items_per_page || process.env.ITEMS_PER_PAGE) || 20, items_per_page: parseInt(dbSettings.items_per_page || process.env.ITEMS_PER_PAGE) || 20,
refresh_interval: parseInt(dbSettings.refresh_interval || process.env.REFRESH_INTERVAL) || 5000, refresh_interval: parseInt(dbSettings.refresh_interval || process.env.REFRESH_INTERVAL) || 5000,
theme: dbSettings.theme || process.env.THEME || 'dark', theme: 'dark',
incident_failure_threshold: parseInt(dbSettings.incident_failure_threshold || process.env.INCIDENT_FAILURE_THRESHOLD) || 10, incident_failure_threshold: parseInt(dbSettings.incident_failure_threshold || process.env.INCIDENT_FAILURE_THRESHOLD) || 10,
webhook_template: dbSettings.webhook_template || process.env.WEBHOOK_TEMPLATE || '', webhook_template: dbSettings.webhook_template || process.env.WEBHOOK_TEMPLATE || '',
}; };
@@ -747,7 +753,7 @@ ESCALATION_HOURS=${escalation_hours || 4}
DEFAULT_SORT=${default_sort || 'name'} DEFAULT_SORT=${default_sort || 'name'}
ITEMS_PER_PAGE=${items_per_page || 20} ITEMS_PER_PAGE=${items_per_page || 20}
REFRESH_INTERVAL=${refresh_interval || 5000} REFRESH_INTERVAL=${refresh_interval || 5000}
THEME=${theme || 'dark'} THEME=dark
INCIDENT_FAILURE_THRESHOLD=${incident_failure_threshold || 10} INCIDENT_FAILURE_THRESHOLD=${incident_failure_threshold || 10}
WEBHOOK_TEMPLATE=${webhook_template || ''} WEBHOOK_TEMPLATE=${webhook_template || ''}
`; `;
@@ -782,7 +788,7 @@ WEBHOOK_TEMPLATE=${webhook_template || ''}
process.env.DEFAULT_SORT = default_sort || 'name'; process.env.DEFAULT_SORT = default_sort || 'name';
process.env.ITEMS_PER_PAGE = String(items_per_page || 20); process.env.ITEMS_PER_PAGE = String(items_per_page || 20);
process.env.REFRESH_INTERVAL = String(refresh_interval || 5000); process.env.REFRESH_INTERVAL = String(refresh_interval || 5000);
process.env.THEME = theme || 'dark'; process.env.THEME = 'dark';
process.env.INCIDENT_FAILURE_THRESHOLD = String(incident_failure_threshold || 10); process.env.INCIDENT_FAILURE_THRESHOLD = String(incident_failure_threshold || 10);
process.env.WEBHOOK_TEMPLATE = webhook_template || ''; process.env.WEBHOOK_TEMPLATE = webhook_template || '';
@@ -814,7 +820,7 @@ WEBHOOK_TEMPLATE=${webhook_template || ''}
{ key: 'items_per_page', value: String(items_per_page || 20) }, { key: 'items_per_page', value: String(items_per_page || 20) },
{ key: 'refresh_interval', value: String(refresh_interval || 5000) }, { key: 'refresh_interval', value: String(refresh_interval || 5000) },
{ key: 'auto_cleanup_enabled', value: String(auto_cleanup_enabled || false) }, { key: 'auto_cleanup_enabled', value: String(auto_cleanup_enabled || false) },
{ key: 'theme', value: theme || 'dark' }, // theme is always dark; skip saving to avoid stale overrides
{ key: 'incident_failure_threshold', value: String(incident_failure_threshold || 10) }, { key: 'incident_failure_threshold', value: String(incident_failure_threshold || 10) },
]; ];