diff --git a/.Jules/changelog.md b/.Jules/changelog.md index d438210..f9bd452 100644 --- a/.Jules/changelog.md +++ b/.Jules/changelog.md @@ -7,6 +7,8 @@ ## [Unreleased] ### Added +- Global `ErrorBoundary` component with dual-theme support (`Glassmorphism`/`Neobrutalism`) to prevent white screen of death. +- Recovery options for users when errors occur ("Try Again" and "Back to Home"). - Inline form validation in Auth page with real-time feedback and proper ARIA accessibility support (`aria-invalid`, `aria-describedby`, `role="alert"`). - Dashboard skeleton loading state (`DashboardSkeleton`) to improve perceived performance during data fetch. - Comprehensive `EmptyState` component for Groups and Friends pages to better guide new users. diff --git a/.Jules/todo.md b/.Jules/todo.md index 894e27f..d261d61 100644 --- a/.Jules/todo.md +++ b/.Jules/todo.md @@ -34,12 +34,10 @@ - Impact: Guides new users, makes app feel polished - Size: ~70 lines -- [ ] **[ux]** Error boundary with retry for API failures - - Files: Create `web/components/ErrorBoundary.tsx`, wrap app - - Context: Catch errors gracefully with retry button - - Impact: App doesn't crash, users can recover - - Size: ~60 lines - - Added: 2026-01-01 +- [x] **[ux]** Error boundary with retry for API failures + - Completed: 2026-01-20 + - Files modified: `web/components/ErrorBoundary.tsx`, `web/App.tsx` + - Impact: Catches unexpected runtime errors and provides a branded recovery UI (try again / back to home) that supports both themes. ### Mobile diff --git a/web/App.tsx b/web/App.tsx index 1461005..bc12083 100644 --- a/web/App.tsx +++ b/web/App.tsx @@ -5,6 +5,7 @@ import { ThemeWrapper } from './components/layout/ThemeWrapper'; import { AuthProvider, useAuth } from './contexts/AuthContext'; import { ThemeProvider } from './contexts/ThemeContext'; import { ToastProvider } from './contexts/ToastContext'; +import { ErrorBoundary } from './components/ErrorBoundary'; import { ToastContainer } from './components/ui/Toast'; import { Auth } from './pages/Auth'; import { Dashboard } from './pages/Dashboard'; @@ -51,8 +52,10 @@ const App = () => { + - + + diff --git a/web/components/ErrorBoundary.tsx b/web/components/ErrorBoundary.tsx new file mode 100644 index 0000000..fe359bf --- /dev/null +++ b/web/components/ErrorBoundary.tsx @@ -0,0 +1,90 @@ +import React, { Component, ErrorInfo, ReactNode } from 'react'; +import { useTheme } from '../contexts/ThemeContext'; +import { Card } from './ui/Card'; +import { Button } from './ui/Button'; +import { AlertTriangle, Home, RefreshCw } from 'lucide-react'; + +// Functional component for the UI to use hooks like useTheme +const ErrorFallback: React.FC<{ + error: Error | null; + resetErrorBoundary: () => void; +}> = ({ error, resetErrorBoundary }) => { + // style is used by Card internally, we don't need it here unless we have specific styles + + return ( +
+ +
+ +
+ +

Something went wrong

+ +

+ {error?.message || "An unexpected error occurred. Please try again."} +

+ +
+ + + +
+
+
+ ); +}; + +interface ErrorBoundaryProps { + children: ReactNode; +} + +interface ErrorBoundaryState { + hasError: boolean; + error: Error | null; +} + +export class ErrorBoundary extends Component { + constructor(props: ErrorBoundaryProps) { + super(props); + this.state = { hasError: false, error: null }; + } + + static getDerivedStateFromError(error: Error): ErrorBoundaryState { + return { hasError: true, error }; + } + + componentDidCatch(error: Error, errorInfo: ErrorInfo) { + console.error('ErrorBoundary caught an error:', error, errorInfo); + } + + resetErrorBoundary = () => { + this.setState({ hasError: false, error: null }); + }; + + render() { + if (this.state.hasError) { + return ( + + ); + } + + return this.props.children; + } +}