Files
Jyotisha/frontend/src/app/error.tsx
T
jesse-uxandGrok (agent loop) 689e01296e
Independent Staging Quality Gate / validate (push) Failing after 9m7s
Independent Staging Quality Gate / publish (push) Skipped
组件库收尾:删掉没人用的旧样式,检查名单只留绘制例外(#111)。
globals.css 从 7249 行减到 7011 行,删了 56 个已经没人用的类,16 个关键帧都还在用。手写控件名单从 9 个文件收到 2 个:天空绘制和校正顶栏探头。星盘和星图的图标豁免仍在规则里。设计说明改成以 shadcn base-nova 和 Motion 预设为准。页面用法没有再改。

自测:tsc --noEmit 退出码 0;frontend 下 npm run lint 0 error、122 warning;白名单、样式隔离、时间线和错误边界测试 18 条通过、失败 0、取消 0;npm run build 后 / 仍是 Static。首屏 JS gzip-9 相对 728ead88 从 644683 到 648993(+0.67%)。没有跑全量 npm test、Python 快速门和 test:db。

Co-Authored-By: Grok (agent loop)
2026-10-25 06:56:39 +08:00

150 lines
4.2 KiB
TypeScript

"use client";
// These pages sit in the shared root layout segment and must not import the
// site stylesheet — that would drag the chat styles onto every admin route — so
// they cannot read a single design token. They restate the handful they need,
// in both themes, and those values are kept in step with the palette by hand.
import { useEffect } from "react";
import { TriangleAlert } from "lucide-react";
import Link from "next/link";
import { Button } from "@/components/ui/button";
const canvas = "var(--bp-canvas)";
const ink = "var(--bp-ink)";
const inkSecondary = "var(--bp-ink-soft)";
const danger = "var(--bp-danger)";
const border = "var(--bp-border)";
const action = "var(--bp-action)";
const focus = "var(--bp-action)";
const actionStyle = {
alignItems: "center",
borderRadius: "12px",
display: "inline-flex",
fontSize: "14px",
fontWeight: 500,
justifyContent: "center",
minHeight: "44px",
minWidth: "88px",
padding: "0 20px",
textDecoration: "none",
} as const;
export default function RootError({
error,
reset,
}: {
error: Error & { digest?: string };
reset: () => void;
}) {
useEffect(() => {
console.error("app root error", error.digest ?? error.message);
}, [error]);
return (
<main
style={{
alignItems: "center",
background: canvas,
color: ink,
display: "flex",
flexDirection: "column",
fontFamily:
'-apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif',
gap: "16px",
justifyContent: "center",
minHeight: "100vh",
padding: "48px 24px",
textAlign: "center",
}}
>
<style>{`
:root {
color-scheme: light;
--bp-canvas: #fbfaf7;
--bp-ink: #1d1d1f;
--bp-ink-soft: #5f5f59;
--bp-border: #d8d6cf;
--bp-action: #85432f;
--bp-danger: #9a2f2f;
}
@media (prefers-color-scheme: dark) {
:root:not([data-theme="light"]) {
color-scheme: dark;
--bp-canvas: #262624;
--bp-ink: #f2f0ea;
--bp-ink-soft: #b3afa4;
--bp-border: #3c3b37;
--bp-action: #d78064;
--bp-danger: #e08573;
}
}
:root[data-theme="dark"] {
color-scheme: dark;
--bp-canvas: #262624;
--bp-ink: #f2f0ea;
--bp-ink-soft: #b3afa4;
--bp-border: #3c3b37;
--bp-action: #d78064;
--bp-danger: #e08573;
}
.root-error-action:focus-visible { outline: 3px solid ${focus}; outline-offset: 2px; }
`}</style>
<TriangleAlert aria-hidden="true" color={danger} size={32} />
<div role="alert">
<h1 style={{ color: ink, fontSize: "20px", fontWeight: 600, margin: "0 0 12px" }}>
页面出错了
</h1>
<p style={{ color: inkSecondary, fontSize: "14px", lineHeight: 1.7, margin: 0, maxWidth: "28rem" }}>
页面渲染时发生异常,已保存的对话不受影响。可以重试,或返回对话首页。
</p>
</div>
{error.digest ? (
<p style={{ color: inkSecondary, fontSize: "12px", lineHeight: 1.7, margin: 0, maxWidth: "28rem" }}>
错误编号 <code style={{ fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace" }}>{error.digest}</code>
,反馈问题时请一并提供。
</p>
) : null}
<div
style={{
display: "flex",
flexWrap: "wrap",
gap: "12px",
justifyContent: "center",
marginTop: "8px",
}}
>
<Button
className="root-error-action"
onClick={() => reset()}
style={{
...actionStyle,
background: action,
border: "1px solid transparent",
color: canvas,
cursor: "pointer",
}}
type="button"
>
重试
</Button>
<Link
className="root-error-action"
href="/"
style={{
...actionStyle,
background: canvas,
border: `1px solid ${border}`,
color: ink,
}}
>
返回对话
</Link>
</div>
</main>
);
}