An open-source, faster Devin alternative
TypeScript
feat(web): error boundaries (no more white-screen on a render throw)
Igor Zalutski6e6c676295a9
diff --git a/web/src/components/app-shell.tsx b/web/src/components/app-shell.tsxindex b841f9bf..64a252e5 100644--- a/web/src/components/app-shell.tsx+++ b/web/src/components/app-shell.tsx@@ -33,6 +33,7 @@ import {DropdownMenuSeparator,DropdownMenuTrigger,} from '@/components/ui/dropdown-menu'+import { ErrorBoundary } from '@/components/error-boundary'import { cn } from '@/lib/utils'type NavItem = { to: string; label: string; icon: LucideIcon; end?: boolean }@@ -194,6 +195,7 @@ function HaltBanner() {export default function AppShell() {const [drawerOpen, setDrawerOpen] = useState(false)+ const location = useLocation()return (<div className="bg-background text-foreground min-h-screen font-sans">@@ -236,15 +238,18 @@ export default function AppShell() {<div className="md:pt-16 md:pl-60"><HaltBanner /><main className="mx-auto max-w-7xl px-4 py-6 sm:px-8">- <Suspense- fallback={- <div className="flex min-h-[60vh] items-center justify-center">- <Loader2 className="text-muted-foreground size-5 animate-spin" />- </div>- }- >- <Outlet />- </Suspense>+ {/* Keyed by route so a page error clears when you navigate away. */}+ <ErrorBoundary key={location.pathname}>+ <Suspense+ fallback={+ <div className="flex min-h-[60vh] items-center justify-center">+ <Loader2 className="text-muted-foreground size-5 animate-spin" />+ </div>+ }+ >+ <Outlet />+ </Suspense>+ </ErrorBoundary></main></div></div>diff --git a/web/src/components/error-boundary.tsx b/web/src/components/error-boundary.tsxnew file mode 100644index 00000000..593ebcd9--- /dev/null+++ b/web/src/components/error-boundary.tsx@@ -0,0 +1,64 @@+import { Component, type ReactNode } from 'react'+import { TriangleAlert } from 'lucide-react'+import { Button } from '@/components/ui/button'+import { EmptyState } from '@/components/empty-state'++interface Props {+ children: ReactNode+ /** Render the recovery UI; `reset` clears the error and re-renders children. */+ fallback?: (reset: () => void) => ReactNode+}++interface State {+ error: Error | null+}++/**+ * Catches render-time errors in its subtree so an unexpected throw shows a+ * recovery UI instead of a blank white screen. Pair it with a `key` (e.g. the+ * route pathname) to auto-reset on navigation.+ */+export class ErrorBoundary extends Component<Props, State> {+ state: State = { error: null }++ static getDerivedStateFromError(error: Error): State {+ return { error }+ }++ componentDidCatch(error: Error, info: { componentStack?: string | null }) {+ console.error('Unhandled UI error:', error, info.componentStack)+ }++ reset = () => this.setState({ error: null })++ render() {+ if (this.state.error) {+ return this.props.fallback ? (+ this.props.fallback(this.reset)+ ) : (+ <DefaultErrorFallback onRetry={this.reset} />+ )+ }+ return this.props.children+ }+}++export function DefaultErrorFallback({ onRetry }: { onRetry: () => void }) {+ return (+ <EmptyState+ icon={TriangleAlert}+ title="Something went wrong"+ description="This view hit an unexpected error. Try again, or reload the page if it keeps happening."+ action={+ <div className="flex gap-2">+ <Button variant="outline" size="sm" onClick={onRetry}>+ Try again+ </Button>+ <Button size="sm" onClick={() => window.location.reload()}>+ Reload+ </Button>+ </div>+ }+ />+ )+}diff --git a/web/src/main.tsx b/web/src/main.tsxindex b5c92338..904c5351 100644--- a/web/src/main.tsx+++ b/web/src/main.tsx@@ -6,6 +6,10 @@ import posthog from 'posthog-js'import { PostHogProvider } from '@posthog/react'import App from './App'import { Toaster } from './components/ui/sonner'+import {+ ErrorBoundary,+ DefaultErrorFallback,+} from './components/error-boundary'import './index.css'const queryClient = new QueryClient({@@ -32,7 +36,15 @@ ReactDOM.createRoot(document.getElementById('root')!).render(<PostHogProvider client={posthog}><QueryClientProvider client={queryClient}><BrowserRouter>- <App />+ <ErrorBoundary+ fallback={(reset) => (+ <div className="bg-background flex min-h-screen items-center justify-center">+ <DefaultErrorFallback onRetry={reset} />+ </div>+ )}+ >+ <App />+ </ErrorBoundary><Toaster theme="light" richColors closeButton /></BrowserRouter></QueryClientProvider>