Skip to content

Commit 8ccd41a

Browse files
author
designcise
committed
fix: defaultTheme is only considered when no theme pref is stored
1 parent f78e50d commit 8ccd41a

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/component/AntiFlickerScript.jsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ export default memo(
66
const { [themes.auto]: _, ...colors } = palette
77
const classList = Object.values(colors).join("','")
88
const preferredTheme = `localStorage.getItem('${storageKey}')`
9-
const fallbackTheme =
10-
defaultTheme && defaultTheme !== themes.auto
11-
? `'${getColorByTheme(defaultTheme)}'`
12-
: `(window.matchMedia('(prefers-color-scheme: ${colors.dark})').matches?'${colors.dark}':'${colors.light}')`
9+
const fallbackTheme = `(window.matchMedia('(prefers-color-scheme: ${colors.dark})').matches?'${colors.dark}':'${colors.light}')`
1310
const script =
1411
'(function(root){' +
15-
`const pref=${preferredTheme};` +
12+
`const pref=${preferredTheme}??'${getColorByTheme(defaultTheme)}';` +
1613
`const theme=(pref&&pref!=='${themes.auto}')?pref:${fallbackTheme};` +
1714
`root.classList.remove('${classList}');root.classList.add(theme);root.style.colorScheme=theme;` +
1815
`})(document.documentElement)`

0 commit comments

Comments
 (0)