mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 05:20:33 +08:00
URL-based chat routing, Snow theme, WebSocket heartbeat & auto-reconnect, ChatComposer perf optimization, embedding provider registry overhaul, Serper search provider, streaming idle timeout, and expanded test suite. Made-with: Cursor
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
"use client";
|
|
|
|
/**
|
|
* ThemeScript - Initializes theme from localStorage before React hydration
|
|
* This prevents the flash of wrong theme on page load
|
|
*/
|
|
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 {
|
|
// Use system preference if not set
|
|
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) {
|
|
// Silently fail - localStorage may be disabled
|
|
}
|
|
})();
|
|
`;
|
|
|
|
return (
|
|
<script
|
|
dangerouslySetInnerHTML={{ __html: themeScript }}
|
|
suppressHydrationWarning
|
|
/>
|
|
);
|
|
}
|