{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "error-fallback",
  "type": "registry:ui",
  "title": "Error Fallback",
  "description": "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…",
  "author": "ofri-peretz <https://github.com/ofri-peretz>",
  "categories": [
    "feedback",
    "pattern"
  ],
  "dependencies": [],
  "registryDependencies": [
    "https://ds.interlace.tools/r/interlace-base.json",
    "https://ds.interlace.tools/r/button.json",
    "https://ds.interlace.tools/r/cn.json",
    "https://ds.interlace.tools/r/error-report-core.json",
    "https://ds.interlace.tools/r/error-report-model.json",
    "https://ds.interlace.tools/r/typography.json"
  ],
  "files": [
    {
      "path": "registry/interlace-ui/patterns/error-fallback.tsx",
      "target": "components/ui/patterns/error-fallback.tsx",
      "type": "registry:ui",
      "content": "'use client';\n\nimport * as React from 'react';\n\n// @interlace/error-fallback v1.0.1 — Interlace design system.\n// Docs, props and live preview: https://ds.interlace.tools/c/error-fallback\n// What changed since: https://ds.interlace.tools/c/error-fallback#history\n// Generated banner — keep it, the upgrade diff reads this version.\n\n/**\n * @interlace/ui — ErrorFallback\n *\n * What a screen shows when it crashes, instead of a blank page or a red box. Plain words, a Try\n * again button, a way out, and a short reference a person can quote. It reports the error once,\n * on mount, through `reportError` (or the `report` you pass), and imports no router: it takes the\n * `{ error, reset }` that Next and Remix hand a boundary, or the `{ error, retry }` that Expo\n * Router hands one.\n *\n * ## Next, `app/error.tsx` (the app's code, not the kit's)\n *\n *   'use client';\n *   // import { ErrorFallback } where the kit puts it in your app\n *   export default function Error({ error, reset }: { error: Error; reset: () => void }) {\n *     return <ErrorFallback error={error} reset={reset} where=\"route\" onBack={() => history.back()} />;\n *   }\n *\n * ## Expo Router, `export function ErrorBoundary` (the app's code; the native component)\n *\n *   import { ErrorFallback } from '@interlace/native';\n *   export function ErrorBoundary({ error, retry }: { error: Error; retry: () => void }) {\n *     return <ErrorFallback error={error} retry={retry} where=\"route: play\" />;\n *   }\n *\n * ## A crash service, ten lines (the app's code): the reporter is the only seam\n *\n *   import { setReporter } from '@interlace/ui/error-report';\n *   setReporter((report) => {\n *     crashService.capture({ place: report.where, message: report.message, stack: report.stack,\n *       fatal: report.fatal, times: report.count });\n *   });\n *   // `report` was redacted and trimmed before it got here. Hand the service nothing else.\n *\n * ## What a report holds, and what it never holds\n *\n * | Holds                                              | Never holds                         |\n * | -------------------------------------------------- | ----------------------------------- |\n * | `where`, which the developer named                 | props, state, storage contents      |\n * | `message`, redacted then trimmed to 300 characters | the URL's query or hash             |\n * | `stack`, redacted then trimmed to 12 lines         | a name, an email, any device id     |\n * | a time, a count, a random id, `fatal`              |                                     |\n *\n * The fallback itself renders neither the message nor the stack: a person does not need a stack,\n * and a stack can hold what they typed. Both are in the log.\n *\n * ## Anatomy\n *\n *   ErrorFallback             (section — data-slot=\"error-fallback\", role=\"alert\", @container)\n *     ├─ title                (h2, tabIndex -1, takes focus on mount)\n *     ├─ description          (p)\n *     ├─ reassurance          (optional node: 'Your progress is saved.' only if the app is sure)\n *     ├─ actions              (Try again, primary; Go back, ghost, when `onBack` is given)\n *     └─ reference            (p, muted: 'Reference: ab12', when `showReference`)\n *\n * ## States\n *\n * | State                              | What it shows                                              |\n * | ---------------------------------- | ---------------------------------------------------------- |\n * | First render                       | Title, description, actions; `report` runs once in an effect |\n * | Retry pressed                      | `reset` or `retry` runs; the router replaces the fallback  |\n * | Neither `reset` nor `retry`        | No Try again, a description that does not promise one, a dev warning |\n * | No `onBack`                        | One button                                                 |\n * | Same `error` re-rendered           | Not reported again                                         |\n * | A new `error`                      | A new report                                               |\n *\n * ## Accessibility\n *\n * On mount focus moves to the title, once, so a keyboard or screen-reader user lands on it instead\n * of on nothing; `role=\"alert\"` reads title and description once. The two actions are named by\n * their visible text (WCAG 2.5.3) and take the Button's 44 px touch target. No motion.\n *\n * ## MIN_VIEWPORT — 320\n *\n * The buttons stack at full width below 20rem of the fallback's own width (`@container`), and sit\n * side by side from it. Logical properties only, so the order follows reading order in RTL.\n *\n * | Rule | Concept                  | Where in this file                                          |\n * | ---- | ------------------------ | ----------------------------------------------------------- |\n * | R4   | Extends native el        | `React.ComponentProps<'section'>`                           |\n * | R6   | data-slot per part       | error-fallback, error-fallback-title, -description, -actions, -reference |\n * | R7   | className merged + rest  | `cn(…, className)` + `{...props}`                           |\n * | R8   | No `isXxx`               | `showReference` is a behaviour switch, not a variant        |\n * | R10  | Composition seam         | `report` (a function, never a vendor prop), `reassurance`   |\n * | R14  | Declares min viewport    | `data-min-viewport` + exported const                        |\n * | R19  | Tokens only              | Typography tones; Button variants                           |\n * | R25  | Client component         | One effect: report once, move focus once                    |\n * | R26  | A11y                     | `role=\"alert\"`, focus to the title, named actions           |\n */\n\nimport { cn } from '@/lib/utils';\nimport {\n  isDevelopment,\n  referenceOf,\n  resolveFallbackLabels,\n  type ErrorFallbackLabels,\n  type ErrorReport,\n} from '@/lib/error-report-model';\nimport { reportError } from '@/lib/error-report-core';\nimport { Button } from '@/components/ui/button';\nimport { Typography } from '@/components/ui/typography';\n\nexport const MIN_VIEWPORT = 320 as const;\n\ninterface ErrorFallbackProps extends Omit<React.ComponentProps<'section'>, 'children'> {\n  /** What the router hands a boundary. */\n  error: unknown;\n  /** Next and Remix call it `reset`; Expo Router calls it `retry`. Pass either. */\n  reset?: () => void;\n  retry?: () => void;\n  /** Where the screen is, for the report: 'route: /play'. Required: a report with no place is noise. */\n  where: string;\n  /** Leave the broken screen. Omit to hide the second button. */\n  onBack?: () => void;\n  /** Extra lines the app is sure of: 'Your progress is saved.' Rendered as given. */\n  reassurance?: React.ReactNode;\n  /** Show the short reference so a person can quote it. @default true */\n  showReference?: boolean;\n  /** Called once on mount with the error; defaults to the default log's `reportError`. */\n  report?: (error: unknown, where: string) => ErrorReport | void;\n  labels?: Partial<ErrorFallbackLabels>;\n}\n\nconst NOT_REPORTED = Symbol('not reported');\n\nfunction ErrorFallback({\n  error,\n  reset,\n  retry,\n  where,\n  onBack,\n  reassurance,\n  showReference = true,\n  report = reportError,\n  labels,\n  className,\n  ...props\n}: ErrorFallbackProps) {\n  const onRetry = reset ?? retry;\n  const copy = resolveFallbackLabels(labels, {\n    canRetry: onRetry !== undefined,\n    canBack: onBack !== undefined,\n  });\n  const titleRef = React.useRef<HTMLParagraphElement>(null);\n  const reported = React.useRef<unknown>(NOT_REPORTED);\n  const [reference, setReference] = React.useState<string | null>(null);\n\n  // Report once per error object, not once per render (and not twice under StrictMode).\n  React.useEffect(() => {\n    if (reported.current === error) return;\n    reported.current = error;\n    const kept = report(error, where);\n    setReference(kept ? referenceOf(kept.id) : null);\n    // `where` and `report` are read once for this error on purpose.\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [error]);\n\n  // Land on the title, once.\n  React.useEffect(() => {\n    titleRef.current?.focus();\n  }, []);\n\n  React.useEffect(() => {\n    if (onRetry === undefined && isDevelopment()) {\n      console.warn('[ErrorFallback] pass `reset` or `retry`, or the screen has no Try again.');\n    }\n  }, [onRetry]);\n\n  return (\n    <section\n      data-slot=\"error-fallback\"\n      data-min-viewport={String(MIN_VIEWPORT)}\n      role=\"alert\"\n      className={cn('@container flex flex-col gap-4 p-6', className)}\n      {...props}\n    >\n      <Typography\n        as=\"h2\"\n        variant=\"h3\"\n        ref={titleRef}\n        tabIndex={-1}\n        data-slot=\"error-fallback-title\"\n      >\n        {copy.title}\n      </Typography>\n      <Typography variant=\"body\" tone=\"muted\" data-slot=\"error-fallback-description\">\n        {copy.description}\n      </Typography>\n      {reassurance}\n      {onRetry !== undefined || onBack !== undefined ? (\n        <div\n          data-slot=\"error-fallback-actions\"\n          className=\"flex flex-col gap-3 @xs:flex-row @xs:flex-wrap\"\n        >\n          {onRetry !== undefined ? (\n            <Button variant=\"default\" onClick={() => onRetry()} className=\"w-full @xs:w-auto\">\n              {copy.retry}\n            </Button>\n          ) : null}\n          {onBack !== undefined ? (\n            <Button variant=\"ghost\" onClick={() => onBack()} className=\"w-full @xs:w-auto\">\n              {copy.back}\n            </Button>\n          ) : null}\n        </div>\n      ) : null}\n      {showReference && reference !== null ? (\n        <Typography as=\"p\" variant=\"caption\" tone=\"muted\" data-slot=\"error-fallback-reference\">\n          {copy.referenceLine(reference)}\n        </Typography>\n      ) : null}\n    </section>\n  );\n}\nErrorFallback.displayName = 'ErrorFallback';\n\nexport { ErrorFallback };\nexport type { ErrorFallbackProps };\n"
    }
  ],
  "meta": {
    "tier": "pattern",
    "client": true,
    "minViewport": 320,
    "loading": false,
    "version": "1.0.1",
    "since": "2.3.0"
  },
  "docs": "## @interlace/error-fallback\n\nInstalled to `components/ui/patterns/error-fallback.tsx`.\n\n```tsx\nimport { /* … */ } from '@/components/ui/patterns/error-fallback';\n```\n\nProps, a11y contract, live preview and source: https://ds.interlace.tools/c/error-fallback\n\nRequires the `@interlace/interlace-base` CSS baseline (installed automatically as a registry dependency). For the Interlace look, also add `@interlace/theme`."
}
