Error Fallback
What a screen shows when it crashes, instead of a blank page or a red box. Plain words, a Try again button, a way out, and a short reference a person can quote. It reports the error once, on mount, through `reportError` (or the `report` you pass), and…
Preview
Rendered from the story the storybook (a11y) CI gate runs axe against — the preview can't show something that hasn't been verified.
Install
Two equivalent paths — the URL works in any shadcn-CLI setup; the alias works once you've registered @interlace in your components.json.
npx shadcn@latest add https://ds.interlace.tools/r/error-fallback.jsonnpx shadcn@latest add @interlace/error-fallbackHistory
This component is at v1.0.1, first shipped in @interlace/ui 2.3.0. The version is stamped as a banner into the file the install writes, so the copy in your tree says which one you have — compare it with the number above before deciding whether to re-run the install.
@interlace/ui 2.4.01 entry
- Addedminor
reportErrorno longer costs a page the whole error log. The small half (the report, the ring of recent reports, the flood rule,installGlobalHandlers) is its own entry,@interlace/ui/error-report-core, 992 B gzipped against 1,412 B before; listeners, restore,installErrorLog,formatReportsand the fallback copy stay in@interlace/ui/error-report-model, imported only where used.@interlace/ui/error-reportstill exports every name it did.createErrorLogis unchanged;extendErrorLogandcreateCoreLogare new. A test bundles the first-load path and fails above 1,000 B gzipped. No new dependency for consumers, no network call.
@interlace/ui 2.3.01 entry
- Addedminor
Nothing fails silently, and a crash never leaves a blank screen.
reportError(error, where)is one function every caught failure goes through: it builds a typed report (the place you name, a message and a stack, redacted then trimmed, a count, a random id), keeps the last 25 in memory, counts a flood of the same failure in one second as one report, and hands each to a pluggable reporter. The default reporter writes one development console line and sends nothing; a crash service is onesetReportercall, and a reporter that throws, or reports from inside itself, is contained.installErrorLog(store)keeps the last reports on the device in an adapter the app passes (loadandsave), so a problem from an earlier session can be read on a diagnostics screen (useRecentErrors(),formatReports()); a store that fails is silent by design.installGlobalHandlers()reportserrorandunhandledrejectionin the browser;installNativeErrorHandler()does the same for React Native and then calls the platform's own handler, so a production crash still crashes.ErrorFallbackis what a screen shows when it crashes: plain words, Try again, a way out, a short reference to quote; it reports once on mount, moves focus to its title, is announced as an alert, never shows the message or the stack, and takes the{ error, reset }of Next and Remix or the{ error, retry }of Expo Router without importing a router.SectionBoundarygains an optionalonError(error, name). No dependency, no network call, no personal data.
Import
3 named exports — pull the parts you need.
import { ErrorBoundary, ErrorFallback, MIN_VIEWPORT } from '@/components/ui/patterns/error-fallback';Anatomy
Extracted from the primitive's JSDoc header. The source is the only documentation that can't drift.
ErrorFallback (section — data-slot="error-fallback", role="alert", @container)
├─ title (h2, tabIndex -1, takes focus on mount)
├─ description (p)
├─ reassurance (optional node: 'Your progress is saved.' only if the app is sure)
├─ actions (Try again, primary; Go back, ghost, when `onBack` is given)
└─ reference (p, muted: 'Reference: ab12', when `showReference`)API reference
Parsed from the type declarations in the source — the same file the install writes into your tree, so this table can't drift from the component you get.
ErrorFallbackProps
Also accepts every <section> attribute.
| Prop | Type | Description |
|---|---|---|
| error* | unknown | What the router hands a boundary. |
| reset | () => void | Next and Remix call it `reset`; Expo Router calls it `retry`. Pass either. |
| retry | () => void | — |
| where* | string | Where the screen is, for the report: 'route: /play'. Required: a report with no place is noise. |
| onBack | () => void | Leave the broken screen. Omit to hide the second button. |
| reassurance | React.ReactNode | Extra lines the app is sure of: 'Your progress is saved.' Rendered as given. |
| showReference | boolean | Show the short reference so a person can quote it. @default true |
| report | (error: unknown, where: string) => ErrorReport | void | Called once on mount with the error; defaults to the default log's `reportError`. |
| labels | Partial<ErrorFallbackLabels> | — |
Accessibility
Every story for this component is rendered headlessly and checked with axe-core (wcag2aa, wcag22aa, best-practice, ACT) on every PR. That gate has no continue-on-error, so what ships has zero known violations.
What follows is what static analysis can see. Axe cannot press a key and never sees an overlay open, so the operable-without-a-mouse claim lives in Behavior instead, where the keyboard path is replayed step by step.
- Focus + keyboard behaviour
- Native element semantics — no interaction layer to get wrong.
- Focus ring (WCAG 2.2 SC 2.4.13)
- Not focusable — no focus indicator required.
- Reduced motion
- No animation to gate.
- ARIA in the source
role="alert"
Examples
7 more states from the same story file.
R-rule compliance
Every primitive in @interlace/ui models to the portable 26-rule floor enforced by the componentApi ESLint preset. The cells below pin exactly where each rule applies in this file.
| Rule | Concept | Where |
|---|---|---|
| R4 | Extends native el | `React.ComponentProps<'section'>` |
| R6 | data-slot per part | error-fallback, error-fallback-title, -description, -actions, -reference |
| R7 | className merged + rest | `cn(…, className)` + `{...props}` |
| R8 | No `isXxx` | `showReference` is a behaviour switch, not a variant |
| R10 | Composition seam | `report` (a function, never a vendor prop), `reassurance` |
| R14 | Declares min viewport | `data-min-viewport` + exported const |
| R19 | Tokens only | Typography tones; Button variants |
| R25 | Client component | One effect: report once, move focus once |
| R26 | A11y | `role="alert"`, focus to the title, named actions |
Minimum viewport
This primitive declares MIN_VIEWPORT = 320 CSS px (DESIGN_PRINCIPLES #14). When mounted in a container narrower than this, the preflight contract draws a dev-mode outline so the regression is visible during local development.
<body data-interlace-dev>...</body>
Add the data-interlace-dev attribute to the body in development builds only — preflight then outlines any primitive whose container is below its declared data-min-viewport.
Dependencies
- Base UI primitive
- Native / no Base UI dependency
- Lucide icons
- none
- NPM dependencies
- none
Source
The full implementation — components/ui/patterns/error-fallback.tsx once installed.
'use client';
import * as React from 'react';
// @interlace/error-fallback v1.0.1 — Interlace design system.
// Docs, props and live preview: https://ds.interlace.tools/c/error-fallback
// What changed since: https://ds.interlace.tools/c/error-fallback#history
// Generated banner — keep it, the upgrade diff reads this version.
/**
* @interlace/ui — ErrorFallback
*
* What a screen shows when it crashes, instead of a blank page or a red box. Plain words, a Try
* again button, a way out, and a short reference a person can quote. It reports the error once,
* on mount, through `reportError` (or the `report` you pass), and imports no router: it takes the
* `{ error, reset }` that Next and Remix hand a boundary, or the `{ error, retry }` that Expo
* Router hands one.
*
* ## Next, `app/error.tsx` (the app's code, not the kit's)
*
…207 more lines…Registry JSON
The raw registry record — what the shadcn CLI fetches.