Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
feat(ui): error boundaries so a render crash can't white-screen the workbench (#719)
Call White54a51676e609
diff --git a/ui/src/App.tsx b/ui/src/App.tsxindex c3777c038..d0809a2ec 100644--- a/ui/src/App.tsx+++ b/ui/src/App.tsx@@ -1,6 +1,7 @@import { BrowserRouter, Routes, Route, Navigate, useLocation, useNavigate } from 'react-router-dom';import { Wizard } from './components/Wizard';import { AppShell } from './components/AppShell';+import { ErrorBoundary } from './components/ui/error-boundary';import { Workbench } from './components/Workbench';import { InboxPage } from './components/workbench/InboxPage';import { SearchPage } from './components/workbench/SearchPage';@@ -377,6 +378,10 @@ function AppRoutes() {function App() {return (+ // Outermost backstop — OUTSIDE every provider, so a crash in a provider itself is contained too+ // (the per-page and per-window boundaries handle granular containment inside). ThemeProvider sets+ // data-theme on <html>, so the fallback still picks up the theme even from out here.+ <ErrorBoundary variant="page"><ThemeProvider><StatusProvider><ToastProvider>@@ -395,6 +400,7 @@ function App() {</ToastProvider></StatusProvider></ThemeProvider>+ </ErrorBoundary>);}diff --git a/ui/src/components/AppShell.tsx b/ui/src/components/AppShell.tsxindex ddf2c043d..5241f4277 100644--- a/ui/src/components/AppShell.tsx+++ b/ui/src/components/AppShell.tsx@@ -13,6 +13,7 @@ import { ThemeToggle } from './ThemeToggle';import { VersionBadge } from './VersionBadge';import { WorkbenchSidebar } from './workbench/WorkbenchSidebar';import { AppsLauncher } from './AppsLauncher';+import { ErrorBoundary } from './ui/error-boundary';import { WindowManagerProvider } from '../context/WindowManagerContext';import { WindowLayer } from './apps/WindowLayer';import { NewSessionSheet } from './workbench/NewSessionSheet';@@ -507,7 +508,12 @@ export const AppShell: React.FC = () => {)}><div className="mx-auto w-full px-4 py-5 md:px-10 md:py-8">- <Outlet />+ {/* A crashing page only replaces the content area — the sidebar + chrome stay usable, and+ navigating elsewhere clears the error without a manual retry. Key on location.key (not+ just pathname) so a query-only navigation (e.g. /search?q=…) also resets. */}+ <ErrorBoundary variant="page" resetKeys={[location.key]}>+ <Outlet />+ </ErrorBoundary></div></main>diff --git a/ui/src/components/apps/AppWindow.tsx b/ui/src/components/apps/AppWindow.tsxindex 492b70a9a..bde6f83a2 100644--- a/ui/src/components/apps/AppWindow.tsx+++ b/ui/src/components/apps/AppWindow.tsx@@ -6,6 +6,7 @@ import { Minus, Plus, X, type LucideIcon } from 'lucide-react';import { APP_REGISTRY } from '../../apps/registry';import { useWindowManager, type WindowInstance } from '../../context/WindowManagerContext';import { clampToLayer, resizeBounds, type ResizeDir } from '../../lib/windowBounds';+import { ErrorBoundary } from '../ui/error-boundary';const RESIZE_HANDLES: { dir: ResizeDir; className: string }[] = [{ dir: 'n', className: 'left-2 right-2 top-0 h-1.5 cursor-ns-resize' },@@ -213,7 +214,11 @@ export const AppWindow: React.FC<{ win: WindowInstance; layerWidth: number; laye</div><div className="min-h-0 flex-1 overflow-hidden">- <Body windowId={win.id} params={win.params} />+ {/* A crashing app only takes down its own window — the shell + other windows stay usable, and+ "Retry" remounts just this app. */}+ <ErrorBoundary variant="inline">+ <Body windowId={win.id} params={win.params} />+ </ErrorBoundary></div>{!win.maximized &&diff --git a/ui/src/components/ui/error-boundary.tsx b/ui/src/components/ui/error-boundary.tsxnew file mode 100644index 000000000..37defe269--- /dev/null+++ b/ui/src/components/ui/error-boundary.tsx@@ -0,0 +1,104 @@+import * as React from 'react';+import { useTranslation } from 'react-i18next';+import { AlertTriangle, RotateCcw } from 'lucide-react';+import clsx from 'clsx';++import { Button } from './button';++// A React error boundary: catches a render error in its subtree and shows a recoverable card instead+// of letting the throw unmount the whole app (a blank white screen). Wrap independent regions — each+// windowed app, the routed page area, and the whole provider stack — so one crashing component only+// takes down its own region, and the rest of the workbench stays usable.+//+// Error boundaries only catch errors thrown during render/lifecycle of their children — not in event+// handlers or async callbacks (those should be try/caught at the call site).++type FallbackRender = (args: { error: unknown; reset: () => void }) => React.ReactNode;++type Props = {+ children: React.ReactNode;+ /** Custom fallback; defaults to a recoverable card that fills its container. */+ fallback?: FallbackRender;+ /**+ * When any value here changes (compared with Object.is), a caught error auto-clears. Pass STABLE+ * values only — e.g. the route key so navigating away from a crashed page recovers. An unstable+ * value (a fresh object/array each render) would reset → re-throw → reset in an infinite loop.+ */+ resetKeys?: unknown[];+ /** `page` fills a tall content area; `inline` is compact for an in-window app body. */+ variant?: 'page' | 'inline';+ onError?: (error: unknown, info: React.ErrorInfo) => void;+};++// `hasError` is tracked separately from the value so a thrown falsy value (`throw null` / `''` / `0`+// is legal JS and possible from third-party code) is still contained instead of falling through.+type State = { hasError: boolean; error: unknown };++function resetKeysChanged(a: unknown[] | undefined, b: unknown[] | undefined): boolean {+ if (a === b) return false;+ if (!a || !b || a.length !== b.length) return true;+ return a.some((value, i) => !Object.is(value, b[i]));+}++export class ErrorBoundary extends React.Component<Props, State> {+ state: State = { hasError: false, error: null };++ static getDerivedStateFromError(error: unknown): State {+ return { hasError: true, error };+ }++ componentDidCatch(error: unknown, info: React.ErrorInfo): void {+ // The boundary swallows the throw so it can never white-screen the app — but the detail must not+ // be lost, so always surface it to the console (and any wired reporter via onError).+ // eslint-disable-next-line no-console+ console.error('ErrorBoundary caught a render error:', error, info.componentStack);+ this.props.onError?.(error, info);+ }++ componentDidUpdate(prev: Props): void {+ if (this.state.hasError && resetKeysChanged(prev.resetKeys, this.props.resetKeys)) {+ this.reset();+ }+ }++ reset = (): void => this.setState({ hasError: false, error: null });++ render(): React.ReactNode {+ if (this.state.hasError) {+ if (this.props.fallback) return this.props.fallback({ error: this.state.error, reset: this.reset });+ return <ErrorFallback error={this.state.error} reset={this.reset} variant={this.props.variant ?? 'page'} />;+ }+ return this.props.children;+ }+}++// Kept dependency-light on purpose: this renders precisely when something else just threw, so it must+// not itself rely on app data that might be the cause. i18n `t` returns the key if missing (no throw).+const ErrorFallback: React.FC<{ error: unknown; reset: () => void; variant: 'page' | 'inline' }> = ({ error, reset, variant }) => {+ const { t } = useTranslation();+ const detail = error instanceof Error ? error.message : typeof error === 'string' ? error : '';+ return (+ <div className={clsx('grid h-full w-full place-items-center bg-surface p-6 text-center', variant === 'page' && 'min-h-[60vh]')}>+ <div className="flex max-w-sm flex-col items-center gap-3">+ <span className="grid size-12 shrink-0 place-items-center rounded-2xl border border-gold/40 bg-gold/[0.08]">+ <AlertTriangle className="size-6 text-gold" />+ </span>+ <div className="text-[15px] font-semibold text-foreground">{t('errorBoundary.title')}</div>+ <div className="text-[12.5px] text-muted">{t('errorBoundary.body')}</div>+ {detail && (+ <div className="max-w-full truncate rounded bg-surface-3 px-2 py-1 font-mono text-[11px] text-muted" title={detail}>+ {detail}+ </div>+ )}+ <div className="mt-1 flex items-center gap-2">+ <Button type="button" size="sm" variant="brand" className="gap-1.5" onClick={reset}>+ <RotateCcw className="size-3.5" /> {t('errorBoundary.retry')}+ </Button>+ <Button type="button" size="sm" variant="outline" onClick={() => window.location.reload()}>+ {t('errorBoundary.reload')}+ </Button>+ </div>+ </div>+ </div>+ );+};diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.jsonindex 396a48096..f3e663736 100644--- a/ui/src/i18n/en.json+++ b/ui/src/i18n/en.json@@ -7,6 +7,12 @@"step2": "Choose “Add to Home Screen”","dismiss": "Collapse"},+ "errorBoundary": {+ "title": "Something went wrong",+ "body": "This part of the app hit an unexpected error. The rest still works — retry, or reload the page.",+ "retry": "Retry",+ "reload": "Reload page"+ },"common": {"back": "Back","continue": "Continue",diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.jsonindex 1dc44e8c9..029e95f49 100644--- a/ui/src/i18n/zh.json+++ b/ui/src/i18n/zh.json@@ -7,6 +7,12 @@"step2": "选「添加到主屏幕」","dismiss": "收起"},+ "errorBoundary": {+ "title": "出了点问题",+ "body": "这部分遇到了意外错误。其他功能仍可正常使用——可以重试,或刷新页面。",+ "retry": "重试",+ "reload": "刷新页面"+ },"common": {"back": "返回","continue": "继续",