UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

56 lines (55 loc) 1.63 kB
import React from "react"; import { jsx } from "react/jsx-runtime"; class Try extends React.Component { state = { error: void 0, componentStack: void 0 }; static getDerivedStateFromError(error) { return { error }; } componentDidCatch(error, errorInfo) { if (this.setState({ componentStack: errorInfo.componentStack || void 0 }), process.env.NODE_ENV === "development") { const routeInfo = this.props.routeInfo; console.error( `[One] Error in route${routeInfo?.routeName ? ` "${routeInfo.routeName}"` : ""}:`, error, ` Component Stack:`, errorInfo.componentStack ); } typeof window < "u" && window.dispatchEvent( new CustomEvent("one-error", { detail: { error: { message: error.message, stack: error.stack, name: error.name }, route: this.props.routeInfo || {}, componentStack: errorInfo.componentStack, timestamp: Date.now(), type: "render" } }) ); } retry = () => new Promise((resolve) => { this.setState({ error: void 0, componentStack: void 0 }, () => { resolve(); }); }); render() { const { error, componentStack } = this.state, { catch: ErrorBoundary, children, routeInfo } = this.props; if (!error) return children; const enhancedRouteInfo = { ...routeInfo, errorType: "render", componentStack }; return /* @__PURE__ */ jsx(ErrorBoundary, { error, retry: this.retry, route: enhancedRouteInfo }); } } export { Try }; //# sourceMappingURL=Try.js.map