From 06bf01639235b15f57f304693b391516231d82fc Mon Sep 17 00:00:00 2001 From: bruno Date: Mon, 13 Jul 2026 21:45:29 -0400 Subject: [PATCH] =?UTF-8?q?fix:=20bfcache=20restore=20=E2=80=94=20theme=20?= =?UTF-8?q?persistant=20apr=C3=A8s=20navigation=20retour?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problème: window.history.back() restaurait la page depuis bfcache → le IIFE initTheme() ne se ré-exécutait pas → le thème dark s'affichait même après avoir sélectionné light Fix: - applySavedTheme() → fonction nommée, pas IIFE - window.addEventListener('pageshow', e.persisted → reapply) - Proper else branch: removeProperty pour le dark mode --- app/templates/base.html | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/app/templates/base.html b/app/templates/base.html index 01b5e51..2ce1902 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -1001,12 +1001,12 @@ }, 300); }); - // Apply saved theme on page load - (function() { + // Apply saved theme on page load (AND on bfcache restore) + function applySavedTheme() { var saved = localStorage.getItem('fd_theme') || 'dark'; + var h = document.documentElement; + h.setAttribute('data-theme', saved); if (saved === 'light') { - var h = document.documentElement; - h.setAttribute('data-theme', 'light'); h.style.setProperty('--bg-primary', '#FFFFFF'); h.style.setProperty('--bg-secondary', '#F7F6F3'); h.style.setProperty('--bg-tertiary', '#EDECE9'); @@ -1015,8 +1015,18 @@ h.style.setProperty('--text-dim', '#9B9A97'); h.style.setProperty('--border', '#E0DFDC'); h.style.setProperty('--border-strong', '#CCCBC8'); + } else { + // Remove light overrides, use CSS defaults + ['bg-primary','bg-secondary','bg-tertiary','text','text-secondary','text-dim','border','border-strong'].forEach(function(v) { + h.style.removeProperty('--'+v); + }); } - })(); + } + applySavedTheme(); + // Re-apply when page is restored from bfcache (e.g. browser back button) + window.addEventListener('pageshow', function(e) { + if (e.persisted) applySavedTheme(); + }); {% block scripts %}{% endblock %}