File size: 732 Bytes
cc54add | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | import { Html, Head, Main, NextScript } from 'next/document';
// Ensures the correct theme class is applied before the app paints
const themeInitScript = `(() => {
try {
const stored = localStorage.getItem('theme');
const prefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
const theme = stored || (prefersDark ? 'dark' : 'light');
if (theme === 'dark') document.documentElement.classList.add('dark');
} catch (e) {}
})();`;
export default function Document() {
return (
<Html lang="en">
<Head />
<body>
<script dangerouslySetInnerHTML={{ __html: themeInitScript }} />
);
}
|