useRecentErrors hook
@interlace/ui — the reports kept so far, as a list that re-renders when one arrives, for a diagnostics screen.
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/use-recent-errors.jsonnpx shadcn@latest add @interlace/use-recent-errorsHistory
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
Single named export.
import { useRecentErrors } from '@/hooks/use-recent-errors';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
- None — semantics come from the element or the Base UI primitive rather than hand-written ARIA.
Dependencies
- Base UI primitive
- Native / no Base UI dependency
- Lucide icons
- none
- NPM dependencies
- none
- Registry dependencies
Source
The full implementation — hooks/use-recent-errors.ts once installed.
'use client';
import * as React from 'react';
// @interlace/use-recent-errors v1.0.1 — Interlace design system.
// Docs, props and live preview: https://ds.interlace.tools/c/use-recent-errors
// What changed since: https://ds.interlace.tools/c/use-recent-errors#history
// Generated banner — keep it, the upgrade diff reads this version.
/**
* @interlace/ui: `useRecentErrors`, the reports kept so far, for a diagnostics screen.
*
* const reports = useRecentErrors();
* <pre>{formatReports(reports)}</pre>
*
* It re-renders when a report arrives, is restored from the device, or the log is cleared. On the
* server it is an empty list, so the markup matches the first client render.
*/
import { defaultErrorLog } from '@/lib/error-report-model';
…8 more lines…Registry JSON
The raw registry record — what the shadcn CLI fetches.