Fix: localStorage preferences take priority over server config

app.js was fetching /api/config/theme and overwriting ROLE_COLORS,
ROLE_STYLE, branding AFTER customize.js had already restored them
from localStorage. Now skips server overrides for any section
where user has local preferences.

Also added branding restore from localStorage on DOMContentLoaded.
This commit is contained in:
you
2026-03-23 03:58:01 +00:00
parent cb68b3e828
commit 0ac7f63035
2 changed files with 11 additions and 8 deletions
+9 -6
View File
@@ -510,8 +510,11 @@ window.addEventListener('DOMContentLoaded', () => {
fetch('/api/config/theme').then(r => r.json()).then(cfg => {
window.SITE_CONFIG = cfg;
// Apply CSS variable overrides from theme.*
if (cfg.theme) {
// User's localStorage preferences take priority over server config
const userTheme = (() => { try { return JSON.parse(localStorage.getItem('meshcore-user-theme') || '{}'); } catch { return {}; } })();
// Apply CSS variable overrides from theme.* (server config, skipped if user has local overrides)
if (cfg.theme && !userTheme.theme && !userTheme.themeDark) {
const root = document.documentElement.style;
const varMap = {
accent: '--accent', accentHover: '--accent-hover',
@@ -533,16 +536,16 @@ window.addEventListener('DOMContentLoaded', () => {
}
}
// Apply node color overrides to ROLE_COLORS and ROLE_STYLE
if (cfg.nodeColors) {
// Apply node color overrides (skip if user has local preferences)
if (cfg.nodeColors && !userTheme.nodeColors) {
for (const [role, color] of Object.entries(cfg.nodeColors)) {
if (window.ROLE_COLORS && role in window.ROLE_COLORS) window.ROLE_COLORS[role] = color;
if (window.ROLE_STYLE && window.ROLE_STYLE[role]) window.ROLE_STYLE[role].color = color;
}
}
// Apply branding
if (cfg.branding) {
// Apply branding (skip if user has local preferences)
if (cfg.branding && !userTheme.branding) {
if (cfg.branding.siteName) {
document.title = cfg.branding.siteName;
const brandText = document.querySelector('.brand-text');
+2 -2
View File
@@ -82,11 +82,11 @@
<script src="vendor/qrcode.js"></script>
<script src="roles.js?v=1774236560"></script>
<script src="customize.js?v=1774238059" onerror="console.error('Failed to load:', this.src)"></script>
<script src="customize.js?v=1774238281" onerror="console.error('Failed to load:', this.src)"></script>
<script src="region-filter.js?v=1774325000"></script>
<script src="hop-resolver.js?v=1774223973"></script>
<script src="hop-display.js?v=1774221932"></script>
<script src="app.js?v=1774234100"></script>
<script src="app.js?v=1774238281"></script>
<script src="home.js?v=1774236560"></script>
<script src="packets.js?v=1774236560"></script>
<script src="map.js?v=1774236560" onerror="console.error('Failed to load:', this.src)"></script>