{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "error-boundary",
  "type": "registry:ui",
  "title": "Error Boundary",
  "description": "The error-boundary primitive.",
  "dependencies": [],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/theme.json"
  ],
  "files": [
    {
      "path": "src/ui/error-boundary.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/ui/error-boundary.tsx",
      "content": "// A boundary around one part of a screen (a card opened over the board, a panel): when its render throws, that part shows the host's\n// fallback with the error, and the rest of the page stays. Without one, React unmounts the whole tree and the person sees a black\n// page with no words (Felix 28 Oct on the Studio board: \"Sometimes when I click a card I get a black screen\").\nimport { Component, type ErrorInfo, type ReactNode } from 'react';\n\nexport interface ErrorBoundaryProps {\n  /** What to show instead: the error and a reset that tries the children again. */\n  fallback: (error: Error, reset: () => void) => ReactNode;\n  /** Told once per catch (log it, report it). */\n  onError?: (error: Error, info: ErrorInfo) => void;\n  /** When this changes, a caught error is forgotten and the children render again (the next card's id). */\n  resetKey?: unknown;\n  children: ReactNode;\n}\n\nexport class ErrorBoundary extends Component<ErrorBoundaryProps, { error: Error | null }> {\n  override state = { error: null as Error | null };\n  static getDerivedStateFromError(error: Error) { return { error }; }\n  override componentDidCatch(error: Error, info: ErrorInfo) { this.props.onError?.(error, info); }\n  override componentDidUpdate(prev: ErrorBoundaryProps) { if (this.state.error && prev.resetKey !== this.props.resetKey) this.setState({ error: null }); }\n  override render() {\n    return this.state.error ? this.props.fallback(this.state.error, () => this.setState({ error: null })) : this.props.children;\n  }\n}\n"
    }
  ]
}
