diff --git a/.Jules/changelog.md b/.Jules/changelog.md index d438210..3f26893 100644 --- a/.Jules/changelog.md +++ b/.Jules/changelog.md @@ -7,6 +7,8 @@ ## [Unreleased] ### Added +- Global `ErrorBoundary` component (`web/components/ErrorBoundary.tsx`) wrapping the web application to catch render errors. +- Dual-theme supported Error UI with "Try Again" (reset boundary) and "Reload Page" options. - 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..7eb868e 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-14 + - Files modified: `web/components/ErrorBoundary.tsx`, `web/App.tsx` + - Impact: Catches global and render errors, presenting a theme-aware UI with retry/reload options instead of a white screen. ### Mobile diff --git a/web/App.tsx b/web/App.tsx index 1461005..66511c9 100644 --- a/web/App.tsx +++ b/web/App.tsx @@ -6,6 +6,7 @@ import { AuthProvider, useAuth } from './contexts/AuthContext'; import { ThemeProvider } from './contexts/ThemeContext'; import { ToastProvider } from './contexts/ToastContext'; import { ToastContainer } from './components/ui/Toast'; +import { ErrorBoundary } from './components/ErrorBoundary'; import { Auth } from './pages/Auth'; import { Dashboard } from './pages/Dashboard'; import { Friends } from './pages/Friends'; @@ -51,8 +52,10 @@ const App = () => { + - + + diff --git a/web/components/ErrorBoundary.tsx b/web/components/ErrorBoundary.tsx new file mode 100644 index 0000000..0a0adae --- /dev/null +++ b/web/components/ErrorBoundary.tsx @@ -0,0 +1,94 @@ +import React, { Component, ErrorInfo, ReactNode } from 'react'; +import { useTheme } from '../contexts/ThemeContext'; +import { THEMES } from '../constants'; +import { Button } from './ui/Button'; +import { Card } from './ui/Card'; +import { AlertTriangle, RefreshCw, Home } from 'lucide-react'; + +interface Props { + children: ReactNode; +} + +interface State { + hasError: boolean; + error: Error | null; +} + +const ErrorFallback = ({ error, resetErrorBoundary }: { error: Error | null, resetErrorBoundary: () => void }) => { + const { style } = useTheme(); + const isNeo = style === THEMES.NEOBRUTALISM; + + return ( +
+ +
+ +
+ +

+ Something went wrong +

+ +
+ {error?.message || "An unexpected error occurred."} +
+ +
+ + + +
+
+
+ ); +}; + +export class ErrorBoundary extends Component { + constructor(props: Props) { + super(props); + this.state = { hasError: false, error: null }; + } + + static getDerivedStateFromError(error: Error): State { + return { hasError: true, error }; + } + + componentDidCatch(error: Error, errorInfo: ErrorInfo) { + console.error("Uncaught error:", error, errorInfo); + } + + resetErrorBoundary = () => { + this.setState({ hasError: false, error: null }); + }; + + render() { + if (this.state.hasError) { + return ( + + ); + } + + return this.props.children; + } +}