fix: bfcache restore — theme persistant après navigation retour
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
This commit is contained in:
+15
-5
@@ -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();
|
||||
});
|
||||
</script>
|
||||
<script src="/static/js/app.js?v=2.4.6" defer></script>
|
||||
{% block scripts %}{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user