Enhance theme switching to handle missing context

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 705f2157-ef97-4fbd-89e4-8c7f2ecaea90
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7ed01c5f-a82d-405a-b728-b2e3d127c60c/70b9c0b1-a5f0-4a27-9a6a-5bb48b9d90b1.jpg
This commit is contained in:
alphaeusmote
2025-04-09 00:47:22 +00:00
parent b466886372
commit 597f859e08
3 changed files with 137 additions and 16 deletions
+18
View File
@@ -9,7 +9,25 @@ import {
} from "@/components/ui/dropdown-menu";
import { useTheme } from "@/hooks/use-theme";
// Fallback toggle without context dependency
export function ThemeToggle() {
// Try/catch block to handle possible context errors
try {
return <ThemeToggleWithContext />;
} catch (error) {
console.error("Theme context error:", error);
// Fallback rendering without context
return (
<Button variant="ghost" size="icon" className="relative h-9 w-9 rounded-md">
<Sun className="h-5 w-5" />
<span className="sr-only">Theme settings</span>
</Button>
);
}
}
// Component that uses the theme context
function ThemeToggleWithContext() {
const { theme, setTheme } = useTheme();
return (