import { Component, type ErrorInfo, type ReactNode } from 'react'; /** What the boundary caught, handed to a render-prop fallback. */ export interface ErrorBoundaryState { error: Error; /** * Runs `onRetry` if the host gave one, then clears the error and re-renders * the children — the same call the default face's action makes, so a host * that replaces the face does not silently lose its own recovery. */ reset: () => void; } export interface ErrorBoundaryProps { children?: ReactNode; /** * Replaces the default face. A function receives the error and a `reset`, * so a host can offer its own recovery instead of a reload. */ fallback?: ReactNode | ((state: ErrorBoundaryState) => ReactNode); /** Report the crash — logging, telemetry, a support channel. */ onError?: (error: Error, info: ErrorInfo) => void; /** * Clear the error when any of these change, so a route change or a new * record recovers without the user pressing anything. */ resetKeys?: readonly unknown[]; /** Overrides for the default face; each falls back to the kit's own copy. */ title?: string; description?: string; /** * Shown as the face's action, and run by a render-prop's `reset` too. * * Called BEFORE the boundary clears. That is enough for a synchronous * recovery — a state flip, a cache clear. It is NOT enough on its own for an * async one: the boundary clears on the next line, so a refetch that has not * resolved re-renders into the same failure. Pair an async recovery with * `resetKeys`, so the settled data is what clears the error. */ onRetry?: () => void; size?: 'sm' | 'md' | 'lg'; } /** * Catches a render error below it and shows the kit's error face instead of * unmounting the tree to a blank page. * * A CLASS COMPONENT, by sanctioned exception — see * `src/docs/23-constraints.mdx` §9. React 18 exposes `getDerivedStateFromError` * and `componentDidCatch` on classes only; there is no hook form, and no * function component can catch a descendant's render error. The exception is * this file, and it is the reason the kit had no boundary at all. * * It catches RENDER errors. An event handler, a timeout or a rejected promise * never reaches it — React does not route those through a boundary — so a host * still handles its own async failures. */ declare class ErrorBoundary extends Component { static displayName: string; state: { error: Error | null; }; static getDerivedStateFromError(error: Error): { error: Error; }; componentDidCatch(error: Error, info: ErrorInfo): void; /** * A changed key clears the error. Compared by identity and in order, so a * host passing a fresh array of the same values does not re-render into the * same failure forever. * * `previousState` is load-bearing. React commits the caught error as an * ordinary update, so the first `componentDidUpdate` after a catch still sees * the props from the last HEALTHY commit. When the prop change is itself what * crashed the child — `resetKeys={[patientId]}` around something that throws * on the new patient, which is the documented use — the keys have moved, and * without this guard the boundary would clear on the very commit that caught * and render straight back into the failure. It settles on the second catch, * but the subtree renders twice and `onError` fires twice for one crash. */ componentDidUpdate(previous: ErrorBoundaryProps, previousState: { error: Error | null; }): void; reset: () => void; handleRetry: () => void; render(): import("react/jsx-runtime").JSX.Element; } export { ErrorBoundary }; //# sourceMappingURL=error-boundary.d.ts.map