diff --git a/src/components/ui/theme-switcher.tsx b/src/components/ui/theme-switcher.tsx index 1d0b75afb..fdee95b11 100644 --- a/src/components/ui/theme-switcher.tsx +++ b/src/components/ui/theme-switcher.tsx @@ -32,41 +32,13 @@ export function ThemeSwitcher({ const t = useTranslations("common"); const [mounted, setMounted] = useState(false); - // Wrap useTheme in try-catch for localStorage error handling - let themeHook: ReturnType | null = null; - try { - themeHook = useTheme(); - } catch (error) { - console.error("Failed to initialize theme:", error); - } + // Always call useTheme unconditionally (Rules of Hooks requirement) + const { theme, setTheme } = useTheme(); useEffect(() => { setMounted(true); }, []); - // Graceful degradation if theme system unavailable - if (!themeHook) { - return ( - - ); - } - - const { theme, setTheme } = themeHook; - // Simplified theme options with better type inference const options = [ { value: "light" as ThemeValue, icon: Sun },