mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 05:59:36 +08:00
Stability release after v1.3.0 covering safer RAG/KB routing, stronger embedding validation, more reliable Docker/TutorBot restarts, Web UX fixes, and Windows/encoding hardening. See assets/releases/ver1-3-1.md for the full notes. Made-with: Cursor
47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
/**
|
|
* ThemeScript - Initializes theme from localStorage before React hydration
|
|
* This prevents the flash of wrong theme on page load.
|
|
*
|
|
* Must be a Server Component: in Next.js / React 19, <script> tags rendered
|
|
* by Client Components are inert on the client. Rendering it from the server
|
|
* inlines the snippet into the SSR HTML so the browser executes it before
|
|
* hydration.
|
|
*/
|
|
export default function ThemeScript() {
|
|
const themeScript = `
|
|
(function() {
|
|
try {
|
|
const stored = localStorage.getItem('deeptutor-theme');
|
|
|
|
document.documentElement.classList.remove('dark', 'theme-glass', 'theme-snow');
|
|
|
|
if (stored === 'dark') {
|
|
document.documentElement.classList.add('dark');
|
|
} else if (stored === 'glass') {
|
|
document.documentElement.classList.add('dark', 'theme-glass');
|
|
} else if (stored === 'snow') {
|
|
document.documentElement.classList.add('theme-snow');
|
|
} else if (stored === 'light') {
|
|
// already clean
|
|
} else {
|
|
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
|
document.documentElement.classList.add('dark');
|
|
localStorage.setItem('deeptutor-theme', 'dark');
|
|
} else {
|
|
localStorage.setItem('deeptutor-theme', 'light');
|
|
}
|
|
}
|
|
} catch (e) {
|
|
/* localStorage may be disabled */
|
|
}
|
|
})();
|
|
`;
|
|
|
|
return (
|
|
<script
|
|
dangerouslySetInnerHTML={{ __html: themeScript }}
|
|
suppressHydrationWarning
|
|
/>
|
|
);
|
|
}
|