{"version":3,"file":"ErrorBoundary.cjs","names":[],"sources":["../../src/error-boundary/ErrorBoundary.tsx"],"sourcesContent":["import { Component } from \"react\";\nimport type { ErrorInfo, ReactNode } from \"react\";\n\nexport interface ErrorBoundaryRenderProps {\n    error: Error;\n    reset: () => void;\n}\n\nexport interface ErrorBoundaryProps {\n    children: ReactNode;\n    /**\n     * Element shown when a descendant throws. Receives the captured error and\n     * a `reset` callback that clears the boundary state.\n     */\n    fallback: ReactNode | ((props: ErrorBoundaryRenderProps) => ReactNode);\n    /** Forwarded to your error tracker (Sentry, Datadog, console, etc.). */\n    onError?: (error: Error, info: ErrorInfo) => void;\n    /**\n     * When any value in this array changes, the boundary automatically resets.\n     * Useful for clearing the error after a navigation.\n     */\n    resetKeys?: readonly unknown[];\n}\n\ninterface ErrorBoundaryState {\n    error: Error | null;\n}\n\nfunction keysChanged(a: readonly unknown[] = [], b: readonly unknown[] = []): boolean {\n    if (a.length !== b.length) return true;\n    for (let i = 0; i < a.length; i++) {\n        if (!Object.is(a[i], b[i])) return true;\n    }\n    return false;\n}\n\n/**\n * Class-based React error boundary with a render-prop or static fallback.\n * Auto-resets when any value in `resetKeys` changes.\n *\n * @example\n * <ErrorBoundary\n *     resetKeys={[location.pathname]}\n *     onError={(err) => reportError(err)}\n *     fallback={({ error, reset }) => (\n *         <ErrorState description={error.message} onRetry={reset} />\n *     )}\n * >\n *     <App />\n * </ErrorBoundary>\n */\nexport class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {\n    override state: ErrorBoundaryState = { error: null };\n\n    static getDerivedStateFromError(error: Error): ErrorBoundaryState {\n        return { error };\n    }\n\n    override componentDidCatch(error: Error, info: ErrorInfo): void {\n        this.props.onError?.(error, info);\n    }\n\n    override componentDidUpdate(previousProps: ErrorBoundaryProps): void {\n        if (this.state.error && keysChanged(previousProps.resetKeys, this.props.resetKeys)) {\n            this.reset();\n        }\n    }\n\n    reset = (): void => {\n        this.setState({ error: null });\n    };\n\n    override render(): ReactNode {\n        const { error } = this.state;\n        if (!error) return this.props.children;\n\n        const { fallback } = this.props;\n        if (typeof fallback === \"function\") {\n            return fallback({ error, reset: this.reset });\n        }\n        return fallback;\n    }\n}\n"],"mappings":"uBA4BA,SAAS,EAAY,EAAwB,CAAC,EAAG,EAAwB,CAAC,EAAY,CAClF,GAAI,EAAE,SAAW,EAAE,OAAQ,MAAO,GAClC,IAAK,IAAI,EAAI,EAAG,EAAI,EAAE,OAAQ,IAC1B,GAAI,CAAC,OAAO,GAAG,EAAE,GAAI,EAAE,EAAE,EAAG,MAAO,GAEvC,MAAO,EACX,CAiBA,IAAa,EAAb,cAAmC,EAAA,SAAkD,CACjF,MAAqC,CAAE,MAAO,IAAK,EAEnD,OAAO,yBAAyB,EAAkC,CAC9D,MAAO,CAAE,OAAM,CACnB,CAEA,kBAA2B,EAAc,EAAuB,CAC5D,KAAK,MAAM,UAAU,EAAO,CAAI,CACpC,CAEA,mBAA4B,EAAyC,CAC7D,KAAK,MAAM,OAAS,EAAY,EAAc,UAAW,KAAK,MAAM,SAAS,GAC7E,KAAK,MAAM,CAEnB,CAEA,UAAoB,CAChB,KAAK,SAAS,CAAE,MAAO,IAAK,CAAC,CACjC,EAEA,QAA6B,CACzB,GAAM,CAAE,SAAU,KAAK,MACvB,GAAI,CAAC,EAAO,OAAO,KAAK,MAAM,SAE9B,GAAM,CAAE,YAAa,KAAK,MAI1B,OAHI,OAAO,GAAa,WACb,EAAS,CAAE,QAAO,MAAO,KAAK,KAAM,CAAC,EAEzC,CACX,CACJ"}