diff --git a/.Jules/changelog.md b/.Jules/changelog.md index d438210..b4d72a0 100644 --- a/.Jules/changelog.md +++ b/.Jules/changelog.md @@ -7,6 +7,7 @@ ## [Unreleased] ### Added +- Error boundary system (`ErrorBoundary` component) to catch React render errors, preventing white screens and offering a "Try Again" recovery option. - 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..99f7492 100644 --- a/.Jules/todo.md +++ b/.Jules/todo.md @@ -34,13 +34,6 @@ - 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 - ### Mobile - [ ] **[ux]** Pull-to-refresh with haptic feedback on all list screens @@ -155,4 +148,9 @@ - Files modified: `web/pages/Auth.tsx` - Impact: Users know immediately if input is valid via inline error messages and red borders. +- [x] **[ux]** Error boundary with retry for API failures + - Completed: 2026-01-13 + - Files modified: `web/components/ErrorBoundary.tsx`, `web/App.tsx` + - Impact: Prevents app crashes from showing blank screens; allows user recovery via retry button. + _No tasks completed yet. Move tasks here after completion._ 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..6390c8c --- /dev/null +++ b/web/components/ErrorBoundary.tsx @@ -0,0 +1,102 @@ +import React, { Component, ErrorInfo, ReactNode } from 'react'; +import { AlertTriangle, RefreshCw, Home } from 'lucide-react'; +import { useTheme } from '../contexts/ThemeContext'; +import { THEMES } from '../constants'; +import { Button } from './ui/Button'; +import { Card } from './ui/Card'; + +interface Props { + children: ReactNode; +} + +interface State { + hasError: boolean; + error: Error | null; +} + +const ErrorFallback: React.FC<{ error: Error | null; resetErrorBoundary: () => void }> = ({ + error, + resetErrorBoundary +}) => { + const { style } = useTheme(); + const isNeo = style === THEMES.NEOBRUTALISM; + + const handleHome = () => { + window.location.href = '/'; + }; + + return ( +
+ +
+
+ +

+ Something went wrong +

+ +

+ We encountered an unexpected error. Please try again. +

+ + {error && ( +
+ {error.message} +
+ )} + +
+ + +
+
+
+ ); +}; + +export class ErrorBoundary extends Component { + public state: State = { + hasError: false, + error: null + }; + + public static getDerivedStateFromError(error: Error): State { + return { hasError: true, error }; + } + + public componentDidCatch(error: Error, errorInfo: ErrorInfo) { + console.error('Uncaught error:', error, errorInfo); + } + + public resetErrorBoundary = () => { + // For a top-level boundary, reloading is often the safest way to recover + window.location.reload(); + }; + + public render() { + if (this.state.hasError) { + return ; + } + + return this.props.children; + } +}