UNPKG

rasengan

Version:

The modern React Framework

40 lines (39 loc) 1.64 kB
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; import { useEffect } from 'react'; import { ErrorBoundaryFallback } from './ErrorBoundaryFallback.js'; import { errorStore } from './error-store.js'; import { ErrorOverlay } from './ErrorOverlay.js'; export function ErrorOverlayProvider({ children, devMode }) { useEffect(() => { if (!devMode) return; const onError = (event) => { errorStore.addError(event.error || new Error(event.message), 'global'); }; const onRejection = (event) => { const error = event.reason instanceof Error ? event.reason : new Error(String(event.reason)); errorStore.addError(error, 'global'); }; window.addEventListener('error', onError); window.addEventListener('unhandledrejection', onRejection); const hot = import.meta.hot; const handleViteError = (data) => { if (data?.err) { errorStore.addError(data.err, 'vite'); } }; if (typeof hot?.on === 'function') { hot.on('vite:error', handleViteError); } return () => { window.removeEventListener('error', onError); window.removeEventListener('unhandledrejection', onRejection); if (typeof hot?.off === 'function') { hot.off('vite:error', handleViteError); } }; }, [devMode]); return (_jsxs(_Fragment, { children: [_jsx(ErrorBoundaryFallback, { children: children }), devMode && _jsx(ErrorOverlay, {})] })); }