import { useStore } from '@nanostores/react';
import { ClientOnly } from 'remix-utils/client-only';
import { chatStore } from '~/lib/stores/chat';
import { classNames } from '~/utils/classNames';
import { HeaderActionButtons } from './HeaderActionButtons.client';
import { ChatDescription } from '~/lib/persistence/ChatDescription.client';
import { Link } from '@remix-run/react';
import { Suspense, lazy, useState, useEffect } from 'react';
// Lazy load the AuthControls component to avoid initialization issues
const LazyAuthControls = lazy(() =>
import('./HeaderAuthControls.client').catch(() => ({
default: () =>
}))
);
// Simple fallback component when auth fails to load
function FallbackAuthUI() {
return (
);
}
// Error boundary for auth controls
function SafeAuthControls() {
const [hasError, setHasError] = useState(false);
useEffect(() => {
// Reset error state if component remounts
return () => setHasError(false);
}, []);
if (hasError) {
return ;
}
return (
}>
setHasError(true)}>
);
}
// Simple error boundary wrapper
function ErrorCatcher({ children, onError }: { children: React.ReactNode; onError: () => void }) {
try {
return children;
} catch (error) {
console.error("Error rendering auth controls:", error);
onError();
return ;
}
}
export function Header() {
const chat = useStore(chatStore);
return (
);
}