{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "error-boundary",
  "type": "registry:component",
  "title": "Error Boundary",
  "description": "Canonical React error boundary for M8 island roots: catches a render throw, reports it through onError, and renders the shared state-error block with a reset action.",
  "registryDependencies": [
    "alert",
    "button"
  ],
  "files": [
    {
      "path": "registry/blocks/feedback/error-boundary.tsx",
      "content": "\"use client\";\n// astro-ui-m8-skin-version: 1.5.3 (A-C6 — run `npx astro-ui-m8-skin-lock` to compare against your installed @mano8/astro-ui-m8)\n\n// Canonical React error boundary for the M8 Astro plugin fleet (`A-C3`).\n//\n// A render-phase throw inside an island unmounts the whole island tree and\n// leaves the host page with a blank region and a console trace. Every plugin\n// mounts its views as islands, so the blast radius is one route's entire\n// interactive surface. This block catches that throw and renders the canonical\n// `state-error` block in its place, so a broken view degrades to the same\n// surface a failed request already degrades to.\n//\n// It is a class on purpose: `getDerivedStateFromError` / `componentDidCatch`\n// have no hook equivalent, and React still offers no function-component API for\n// catching a render throw.\n\nimport * as React from \"react\";\n\nimport { StateError } from \"./state-error\";\n\nexport interface ErrorBoundaryFallbackProps {\n  error: Error;\n  reset: () => void;\n}\n\nexport interface ErrorBoundaryProps {\n  children: React.ReactNode;\n  /**\n   * Replaces the default `state-error` fallback. Receives the caught error and\n   * a `reset` that clears the boundary and re-renders `children`.\n   */\n  fallback?: (props: ErrorBoundaryFallbackProps) => React.ReactNode;\n  /**\n   * Reporting hook. The boundary itself never logs: what a host does with a\n   * caught error — console, Sentry, a toast — is the host's decision.\n   */\n  onError?: (error: Error, info: { componentStack: string }) => void;\n  /**\n   * Clears the boundary when any member changes, so navigating away from the\n   * input that threw recovers without a reload. Compared by `Object.is`,\n   * position by position, exactly as React compares a dependency array.\n   */\n  resetKeys?: readonly unknown[];\n  title?: string;\n  description?: string;\n  retryLabel?: string;\n}\n\ninterface ErrorBoundaryState {\n  error: Error | null;\n}\n\n/**\n * A thrown value is not necessarily an `Error` — `throw \"boom\"` and\n * `throw {code:1}` are legal — so normalize before handing it on. Callers can\n * then rely on `error.message` without a type guard of their own.\n */\nfunction toError(thrown: unknown): Error {\n  if (thrown instanceof Error) return thrown;\n  if (typeof thrown === \"string\") return new Error(thrown);\n  return new Error(\"The view failed to render.\");\n}\n\nfunction resetKeysChanged(\n  previous: readonly unknown[] | undefined,\n  next: readonly unknown[] | undefined,\n): boolean {\n  if (previous === undefined || next === undefined) return false;\n  if (previous.length !== next.length) return true;\n  return previous.some((value, index) => !Object.is(value, next[index]));\n}\n\nexport class ErrorBoundary extends React.Component<\n  ErrorBoundaryProps,\n  ErrorBoundaryState\n> {\n  override state: ErrorBoundaryState = { error: null };\n\n  static getDerivedStateFromError(thrown: unknown): ErrorBoundaryState {\n    return { error: toError(thrown) };\n  }\n\n  override componentDidCatch(thrown: unknown, info: React.ErrorInfo): void {\n    this.props.onError?.(toError(thrown), {\n      componentStack: info.componentStack ?? \"\",\n    });\n  }\n\n  override componentDidUpdate(previous: ErrorBoundaryProps): void {\n    if (this.state.error === null) return;\n    if (!resetKeysChanged(previous.resetKeys, this.props.resetKeys)) return;\n    this.reset();\n  }\n\n  reset = (): void => {\n    this.setState({ error: null });\n  };\n\n  override render(): React.ReactNode {\n    const { error } = this.state;\n    if (error === null) return this.props.children;\n\n    if (this.props.fallback) {\n      return this.props.fallback({ error, reset: this.reset });\n    }\n\n    // The caught message is deliberately *not* rendered. A render throw carries\n    // whatever the failing code put in it — an id, a URL, a parse fragment —\n    // and this fallback is a user-facing surface. A host that wants the detail\n    // reads it from `onError` or renders its own `fallback`.\n    return (\n      <div data-m8-error-boundary=\"fallback\">\n        <StateError\n          title={this.props.title ?? \"This view stopped responding\"}\n          description={\n            this.props.description ??\n            \"The page hit an unexpected error and could not finish rendering.\"\n          }\n          retryLabel={this.props.retryLabel ?? \"Reload this view\"}\n          onRetry={this.reset}\n        />\n      </div>\n    );\n  }\n}\n",
      "type": "registry:component",
      "target": "components/m8-ui/error-boundary.tsx"
    },
    {
      "path": "registry/blocks/state/state-error.tsx",
      "content": "\"use client\";\n// astro-ui-m8-skin-version: 1.5.3 (A-C6 — run `npx astro-ui-m8-skin-lock` to compare against your installed @mano8/astro-ui-m8)\n\nimport * as React from \"react\";\nimport { AlertCircle } from \"lucide-react\";\n\nimport { Alert, AlertDescription, AlertTitle } from \"@/components/ui/alert\";\nimport { Button } from \"@/components/ui/button\";\n\nexport interface StateErrorProps {\n  title?: string;\n  description?: string;\n  retryLabel?: string;\n  onRetry?: () => void;\n  action?: React.ReactNode;\n}\n\nexport function StateError({\n  title = \"Something went wrong\",\n  description = \"The request could not be completed.\",\n  retryLabel = \"Try again\",\n  onRetry,\n  action,\n}: StateErrorProps) {\n  return (\n    <Alert variant=\"destructive\">\n      <AlertCircle className=\"size-4\" aria-hidden=\"true\" />\n      <AlertTitle>{title}</AlertTitle>\n      <AlertDescription>\n        <div className=\"space-y-3\">\n          <p>{description}</p>\n          {onRetry || action ? (\n            <div className=\"flex flex-wrap gap-2\">\n              {onRetry ? (\n                <Button type=\"button\" variant=\"outline\" size=\"sm\" onClick={onRetry}>\n                  {retryLabel}\n                </Button>\n              ) : null}\n              {action}\n            </div>\n          ) : null}\n        </div>\n      </AlertDescription>\n    </Alert>\n  );\n}\n\n",
      "type": "registry:component",
      "target": "components/m8-ui/state-error.tsx"
    }
  ]
}
