Skip to content

Commit 2d43fb1

Browse files
Merge pull request #393 from adamgen/bugfix/392-default-darktheme-setting
fix(website): fix initial theme usage when os is in dark mode
2 parents 2adf927 + a565c90 commit 2d43fb1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

apps/website/src/root.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,14 @@ export default component$(() => {
3939
useContextProvider(ROOT_STORE_CONTEXT_ID, rootStore);
4040

4141
useVisibleTask$(() => {
42-
rootStore.mode =
43-
localStorage.getItem(THEME_STORAGE_KEY) === 'dark' ? 'dark' : 'light';
42+
const userStoredTheme = localStorage.getItem(THEME_STORAGE_KEY);
43+
if (userStoredTheme) {
44+
rootStore.mode = userStoredTheme === 'dark' ? 'dark' : 'light';
45+
} else {
46+
rootStore.mode = window.matchMedia('(prefers-color-scheme: dark)').matches
47+
? 'dark'
48+
: 'light';
49+
}
4450
});
4551

4652
// TODO: remove this old state once refactored

0 commit comments

Comments
 (0)