import * as Sentry from '@sentry/react' import { type ReactNode, useEffect, useRef } from 'react' import { Button } from '@/components/ui/Button' interface FallbackProps { error: Error resetError: () => void } function isChunkLoadError(error: Error): boolean { const msg = error.message || '' return ( msg.includes('dynamically imported module') || msg.includes('Loading chunk') || msg.includes('Failed to fetch') || error.name === 'ChunkLoadError' ) } function DefaultFallback({ error, resetError }: FallbackProps) { const reloadingRef = useRef(false) // Auto-reload on stale chunk errors (happens after deployments) useEffect(() => { if (!isChunkLoadError(error)) return const key = 'rf_boundary_chunk_reload' const lastReload = sessionStorage.getItem(key) const now = Date.now() if (!lastReload || now - Number(lastReload) > 10_000) { sessionStorage.setItem(key, String(now)) reloadingRef.current = true window.location.reload() } }, [error]) return (

Something went wrong

An unexpected error occurred. Please try refreshing the page.

          {error.message}
        
) } interface Props { children: ReactNode fallback?: ReactNode } export function ErrorBoundary({ children, fallback }: Props) { return ( { if (fallback) return fallback as React.ReactElement return }} beforeCapture={(scope, error) => { // Don't report chunk load errors to Sentry — they're deploy artifacts, not bugs if (error && isChunkLoadError(error as Error)) { scope.setLevel('info') scope.setTag('chunk_load_error', 'true') } }} showDialog={false} > {children} ) } export default ErrorBoundary