Speed up init theme

This commit is contained in:
MartinBraquet
2025-10-18 22:43:17 +02:00
parent 1341d1356a
commit 93f3690344
2 changed files with 2 additions and 5 deletions

View File

@@ -40,9 +40,7 @@ const reRenderTheme = () => {
const theme: theme_option | null =
JSON.parse(localStorage.getItem('theme') ?? 'null') ?? 'auto'
const autoDark = window.matchMedia('(prefers-color-scheme: dark)').matches
if (theme === 'dark' || (theme !== 'light' && autoDark)) {
if (theme === 'dark' || (theme !== 'light' && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
document.documentElement.classList.add('dark')
} else {
document.documentElement.classList.remove('dark')

View File

@@ -1,10 +1,9 @@
// run this in <head> as blocking to prevent flash of unstyled content. See theme-provider.tsx
{
const autoDark = window.matchMedia('(prefers-color-scheme: dark)').matches
const localTheme = localStorage.getItem('theme')
const theme = localTheme ? JSON.parse(localTheme) : 'auto'
if (theme === 'dark' || (theme === 'auto' && autoDark)) {
if (theme === 'dark' || (theme === 'auto' && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
document.documentElement.classList.add('dark')
}
}