-
Notifications
You must be signed in to change notification settings - Fork 45
fix(profile): /u/[username] SSR 抓取加重试 + 添加 error 边界 #286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| "use client"; | ||
|
|
||
| // 个人主页路由的错误边界。 | ||
| // | ||
| // 为什么要单独加这个文件: | ||
| // 原先 /u/[username] 的 SSR 抓取如果命中 Cloudflare 偶发 403 / 后端 5xx, | ||
| // 会直接冒泡到 Next 默认的全局错误页("Application error: a server-side exception | ||
| // has occurred while loading involutionhell.com"),用户看到的是一堆 digest 没有 | ||
| // 任何可操作的信息。这里给一个本地化的、带"重试"按钮的降级界面。 | ||
| // | ||
| // 注意: | ||
| // - 必须是 client component("use client"),因为需要 useEffect / onClick。 | ||
| // - 不要依赖任何服务端 state,error 本身就是 SSR 失败的产物。 | ||
| // - reset() 来自 Next,会尝试重新渲染该路由段(会重新触发 SSR fetch),适合瞬时抖动场景。 | ||
|
|
||
| import Link from "next/link"; | ||
| import { useEffect } from "react"; | ||
|
|
||
| export default function ProfileError({ | ||
| error, | ||
| reset, | ||
| }: { | ||
| error: Error & { digest?: string }; | ||
| reset: () => void; | ||
| }) { | ||
| useEffect(() => { | ||
| // 把 digest 和 message 打到浏览器控制台,方便用户把 digest 回贴给我们排查。 | ||
| // 服务端那份 stack 在 Vercel runtime logs 里(fetchProfile 里也已经记录)。 | ||
| console.error("[UserProfile error boundary]", { | ||
| message: error.message, | ||
| digest: error.digest, | ||
| }); | ||
| }, [error]); | ||
|
|
||
| return ( | ||
| <main className="min-h-screen bg-[var(--background)] flex items-center justify-center px-6 py-24"> | ||
| <div className="max-w-xl w-full border border-[var(--foreground)] p-8 lg:p-12 flex flex-col gap-6"> | ||
| <div className="font-mono text-[10px] uppercase tracking-[0.3em] text-[#CC0000]"> | ||
| Profile · Temporary Failure | ||
| </div> | ||
| <h1 className="font-serif text-3xl md:text-4xl font-black uppercase tracking-tight text-[var(--foreground)]"> | ||
| 个人主页暂时加载失败 | ||
| </h1> | ||
| <p className="text-sm leading-relaxed text-neutral-600 dark:text-neutral-400"> | ||
| 服务端在拉取这个用户的资料时遇到了一次瞬时错误(可能是上游 CDN | ||
| 拦截或后端抖动)。通常重试一次就能恢复。 | ||
| </p> | ||
| {error.digest ? ( | ||
| <p className="font-mono text-[10px] uppercase tracking-widest text-neutral-500"> | ||
| Error digest: {error.digest} | ||
| </p> | ||
| ) : null} | ||
| <div className="flex flex-wrap gap-3 pt-2"> | ||
| <button | ||
| type="button" | ||
| onClick={reset} | ||
| className="font-mono text-xs uppercase tracking-widest px-4 py-2 border border-[var(--foreground)] bg-[var(--foreground)] text-[var(--background)] hover:bg-[#CC0000] hover:border-[#CC0000] transition-colors" | ||
| > | ||
| 重试 | ||
| </button> | ||
| <Link | ||
| href="/" | ||
| className="font-mono text-xs uppercase tracking-widest px-4 py-2 border border-[var(--foreground)] hover:bg-[var(--foreground)] hover:text-[var(--background)] transition-colors" | ||
| > | ||
| 返回首页 | ||
| </Link> | ||
| <Link | ||
| href="/rank" | ||
| className="font-mono text-xs uppercase tracking-widest px-4 py-2 border border-[var(--foreground)] hover:bg-[var(--foreground)] hover:text-[var(--background)] transition-colors" | ||
| > | ||
| 查看排行榜 | ||
| </Link> | ||
| </div> | ||
| </div> | ||
| </main> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code logs a
bodySnippet(first 300 chars) from upstream responses into server logs. Even though this only happens on non-2xx, those bodies can still contain sensitive data (e.g., backend error pages, stack traces, Cloudflare challenge HTML). Consider redacting/sanitizing this snippet, logging only whencontent-typeis safe/expected, or logging a hash/length instead of raw body content.