one
Version:
One is a new React Framework that makes Vite serve both native and web.
297 lines (296 loc) • 9.26 kB
JavaScript
import React from "react";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
function ErrorBoundary({
error,
retry,
route
}) {
const isDev = process.env.NODE_ENV === "development";
return React.useEffect(() => {
typeof window < "u" && window.dispatchEvent(new CustomEvent("one-error", {
detail: {
error: {
message: error.message,
stack: error.stack,
name: error.name
},
route: route || {},
timestamp: Date.now(),
type: "render"
}
}));
}, [error, route]), /* @__PURE__ */jsx("div", {
style: {
minHeight: "100vh",
display: "flex",
alignItems: "center",
justifyContent: "center",
backgroundColor: "#0a0a0f",
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif',
color: "#e8e8e8",
padding: "24px"
},
children: /* @__PURE__ */jsxs("div", {
style: {
maxWidth: "600px",
width: "100%",
backgroundColor: "#1a1a2e",
borderRadius: "12px",
boxShadow: "0 8px 32px rgba(0, 0, 0, 0.4)",
overflow: "hidden"
},
children: [/* @__PURE__ */jsxs("div", {
style: {
padding: "16px 20px",
backgroundColor: "#ef4444",
display: "flex",
alignItems: "center",
gap: "12px"
},
children: [/* @__PURE__ */jsxs("svg", {
width: "24",
height: "24",
viewBox: "0 0 24 24",
fill: "none",
stroke: "white",
strokeWidth: "2",
children: [/* @__PURE__ */jsx("circle", {
cx: "12",
cy: "12",
r: "10"
}), /* @__PURE__ */jsx("line", {
x1: "12",
y1: "8",
x2: "12",
y2: "12"
}), /* @__PURE__ */jsx("line", {
x1: "12",
y1: "16",
x2: "12.01",
y2: "16"
})]
}), /* @__PURE__ */jsxs("div", {
children: [/* @__PURE__ */jsx("div", {
style: {
fontWeight: 600,
fontSize: "16px",
color: "white"
},
children: "Something went wrong"
}), route?.pathname && /* @__PURE__ */jsxs("div", {
style: {
fontSize: "13px",
color: "rgba(255,255,255,0.8)",
marginTop: "2px"
},
children: ["on ", route.pathname]
})]
})]
}), /* @__PURE__ */jsxs("div", {
style: {
padding: "20px"
},
children: [/* @__PURE__ */jsx("div", {
style: {
backgroundColor: "#2a2a4a",
borderRadius: "8px",
padding: "16px",
marginBottom: "16px"
},
children: /* @__PURE__ */jsx("div", {
style: {
fontFamily: "monospace",
fontSize: "14px",
lineHeight: "1.5",
color: "#f87171",
wordBreak: "break-word"
},
children: error.message || "An unexpected error occurred"
})
}), isDev && error.stack && /* @__PURE__ */jsxs("details", {
style: {
marginBottom: "16px"
},
children: [/* @__PURE__ */jsx("summary", {
style: {
cursor: "pointer",
fontSize: "13px",
color: "#888",
marginBottom: "8px"
},
children: "Stack trace"
}), /* @__PURE__ */jsx("div", {
style: {
backgroundColor: "#16162a",
borderRadius: "8px",
padding: "12px",
maxHeight: "200px",
overflow: "auto"
},
children: /* @__PURE__ */jsx("pre", {
style: {
fontFamily: "monospace",
fontSize: "11px",
lineHeight: "1.6",
color: "#a0a0a0",
margin: 0,
whiteSpace: "pre-wrap",
wordBreak: "break-word"
},
children: error.stack
})
})]
}), isDev && route && /* @__PURE__ */jsxs("details", {
style: {
marginBottom: "16px"
},
children: [/* @__PURE__ */jsx("summary", {
style: {
cursor: "pointer",
fontSize: "13px",
color: "#888",
marginBottom: "8px"
},
children: "Route info"
}), /* @__PURE__ */jsxs("div", {
style: {
backgroundColor: "#16162a",
borderRadius: "8px",
padding: "12px",
display: "grid",
gridTemplateColumns: "auto 1fr",
gap: "8px",
fontFamily: "monospace",
fontSize: "12px"
},
children: [route.pathname && /* @__PURE__ */jsxs(Fragment, {
children: [/* @__PURE__ */jsx("span", {
style: {
color: "#888"
},
children: "pathname"
}), /* @__PURE__ */jsx("span", {
style: {
color: "#e8e8e8"
},
children: route.pathname
})]
}), route.routeName && /* @__PURE__ */jsxs(Fragment, {
children: [/* @__PURE__ */jsx("span", {
style: {
color: "#888"
},
children: "route"
}), /* @__PURE__ */jsx("span", {
style: {
color: "#e8e8e8"
},
children: route.routeName
})]
}), route.params && Object.keys(route.params).length > 0 && /* @__PURE__ */jsxs(Fragment, {
children: [/* @__PURE__ */jsx("span", {
style: {
color: "#888"
},
children: "params"
}), /* @__PURE__ */jsx("span", {
style: {
color: "#e8e8e8"
},
children: JSON.stringify(route.params)
})]
})]
})]
}), /* @__PURE__ */jsxs("div", {
style: {
display: "flex",
gap: "12px"
},
children: [/* @__PURE__ */jsx("button", {
onClick: () => retry(),
style: {
flex: 1,
padding: "12px 20px",
backgroundColor: "#3b82f6",
color: "white",
border: "none",
borderRadius: "8px",
fontSize: "14px",
fontWeight: 500,
cursor: "pointer",
transition: "background-color 0.15s"
},
onMouseOver: e => {
e.currentTarget.style.backgroundColor = "#2563eb";
},
onMouseOut: e => {
e.currentTarget.style.backgroundColor = "#3b82f6";
},
children: "Try Again"
}), /* @__PURE__ */jsx("button", {
onClick: () => {
typeof window < "u" && (window.location.href = "/");
},
style: {
padding: "12px 20px",
backgroundColor: "transparent",
color: "#888",
border: "1px solid #3a3a5a",
borderRadius: "8px",
fontSize: "14px",
fontWeight: 500,
cursor: "pointer",
transition: "all 0.15s"
},
onMouseOver: e => {
e.currentTarget.style.backgroundColor = "#2a2a4a", e.currentTarget.style.color = "#e8e8e8";
},
onMouseOut: e => {
e.currentTarget.style.backgroundColor = "transparent", e.currentTarget.style.color = "#888";
},
children: "Go Home"
})]
})]
}), isDev && /* @__PURE__ */jsxs("div", {
style: {
padding: "12px 20px",
backgroundColor: "#16162a",
borderTop: "1px solid #2a2a4a",
fontSize: "11px",
color: "#666",
display: "flex",
alignItems: "center",
gap: "8px"
},
children: [/* @__PURE__ */jsxs("svg", {
width: "12",
height: "12",
viewBox: "0 0 24 24",
fill: "none",
stroke: "#666",
strokeWidth: "2",
children: [/* @__PURE__ */jsx("circle", {
cx: "12",
cy: "12",
r: "10"
}), /* @__PURE__ */jsx("path", {
d: "M12 16v-4"
}), /* @__PURE__ */jsx("path", {
d: "M12 8h.01"
})]
}), /* @__PURE__ */jsxs("span", {
children: ["Press", " ", /* @__PURE__ */jsx("kbd", {
style: {
padding: "2px 6px",
backgroundColor: "#2a2a4a",
borderRadius: "4px"
},
children: "Alt+E"
}), " ", "to open Error Panel"]
})]
})]
})
});
}
export { ErrorBoundary };
//# sourceMappingURL=ErrorBoundary.mjs.map