Skip to content

Commit f82c714

Browse files
committed
Fix FOUC
1 parent 537c798 commit f82c714

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

templates/layout.twig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,19 @@
1515
}
1616
</style>
1717
{%- endif %}
18+
<script>
19+
const theme = localStorage.getItem('theme') || 'system';
20+
let current_theme = theme;
1821
22+
if (theme === 'system') {
23+
current_theme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
24+
document.documentElement.setAttribute('color-theme', 'system');
25+
} else {
26+
document.documentElement.setAttribute('color-theme', theme);
27+
}
28+
29+
document.documentElement.classList.toggle('dark', current_theme === 'dark');
30+
</script>
1931
</head>
2032
<body class="bg-gray-100 text-gray-900 dark:text-gray-200 dark:bg-gray-900" data-dashboard="{{ current }}">
2133
<header class="grid md:grid-cols-3 p-4 bg-white dark:bg-gray-800 border-b border-gray-200 dark:border-gray-700">

0 commit comments

Comments
 (0)