mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-04-04 23:03:45 -04:00
Speed up init theme
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -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')
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user