Skip to content

Commit 93f3690

Browse files
committed
Speed up init theme
1 parent 1341d13 commit 93f3690

2 files changed

Lines changed: 2 additions & 5 deletions

File tree

web/hooks/use-theme.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ const reRenderTheme = () => {
4040
const theme: theme_option | null =
4141
JSON.parse(localStorage.getItem('theme') ?? 'null') ?? 'auto'
4242

43-
const autoDark = window.matchMedia('(prefers-color-scheme: dark)').matches
44-
45-
if (theme === 'dark' || (theme !== 'light' && autoDark)) {
43+
if (theme === 'dark' || (theme !== 'light' && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
4644
document.documentElement.classList.add('dark')
4745
} else {
4846
document.documentElement.classList.remove('dark')

web/public/init-theme.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// run this in <head> as blocking to prevent flash of unstyled content. See theme-provider.tsx
22
{
3-
const autoDark = window.matchMedia('(prefers-color-scheme: dark)').matches
43
const localTheme = localStorage.getItem('theme')
54
const theme = localTheme ? JSON.parse(localTheme) : 'auto'
65

7-
if (theme === 'dark' || (theme === 'auto' && autoDark)) {
6+
if (theme === 'dark' || (theme === 'auto' && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
87
document.documentElement.classList.add('dark')
98
}
109
}

0 commit comments

Comments
 (0)