Skip to content

Commit 44d8fdb

Browse files
committed
fix(site-kit): respect system theme preference
When loading the site with 'system' as the set theme, ensure the appropriate system theme gets applied. See #703
1 parent e567c6c commit 44d8fdb

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

packages/site-kit/src/lib/components/ThemeToggle.svelte

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@
1414
if ($theme.preference === 'system') {
1515
const query = window.matchMedia('(prefers-color-scheme: dark)');
1616
17-
return on(query, 'change', (e) => {
17+
function setTheme(e: MediaQueryListEvent | MediaQueryList) {
1818
$theme.current = e.matches ? 'dark' : 'light';
19-
});
19+
}
20+
21+
setTheme(query);
22+
return on(query, 'change', setTheme);
2023
}
2124
});
2225
</script>

0 commit comments

Comments
 (0)