fix: validate persisted theme value before applying

This commit is contained in:
camilleislasse 2026-04-18 08:24:58 +02:00
parent 070898108f
commit f5b1705925

View file

@ -6,7 +6,8 @@
} catch {
// storage unavailable (private mode, quota exceeded)
}
const theme = stored || (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
const storedTheme = ['light', 'dark'].includes(stored) ? stored : null;
const theme = storedTheme || (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
document.documentElement.setAttribute('data-bs-theme', theme);
})();
</script>