"use client"; import React, { Component, ErrorInfo, ReactNode } from "react"; interface Props { children: ReactNode; fallback?: ReactNode; onError?: (error: Error, errorInfo: ErrorInfo) => void; } interface State { hasError: boolean; error?: Error; } export class ErrorBoundary extends Component { public state: State = { hasError: false, }; public static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } public componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.error("ErrorBoundary caught an error:", error, errorInfo); this.props.onError?.(error, errorInfo); } public render() { if (this.state.hasError) { if (this.props.fallback) { return this.props.fallback; } return (
⚠️

Something went wrong

We're sorry, but something unexpected happened. Please try refreshing the page.

{process.env.NEXT_PUBLIC_APP_ENV !== "production" && this.state.error && (
Error Details (Development Only)
                {this.state.error.stack}
              
)}
); } return this.props.children; } } // Specialized error boundaries for different sections export function NavbarErrorBoundary({ children }: { children: ReactNode }) { return (
} > {children} ); } export function CartErrorBoundary({ children }: { children: ReactNode }) { return (
🛒

Cart temporarily unavailable

} > {children} ); } export function ProductErrorBoundary({ children }: { children: ReactNode }) { return (
📦

Product information temporarily unavailable

} > {children} ); }