fix(leaderboard): fallback 非数组覆盖空 (Copilot CR PR #326)#328
Merged
longsizhuo merged 1 commit intomainfrom Apr 27, 2026
Merged
Conversation
Copilot CR (PR #326) 反馈 之前 fallback 只要 JSON.parse 成功就 preserveExisting=true,包括对象、null 等非数组类型也会被"维持原状"。但下游有多处 `import leaderboardData from "@/generated/site-leaderboard.json"` 直接 .filter/.map(如 Hero 的 top3、 /rank 页),一旦内容不是数组,整个 Next build 就会因 "filter is not a function" 直接挂掉。 修法 四档 fallback: 1. 非空数组 → 保留(warn 多少条) 2. 空数组 → 保留空数组(语义合法,下游 .filter 不挂) 3. JSON 损坏 / 非数组 → 兜底覆盖为 [](避免下游 import 后 type error) 4. 文件不存在 → 兜底覆盖为 [] 效果 - 任何已存在的合法数组都不被无故覆盖 - 任何非数组数据都强制规范化为 [],下游 .filter/.map 永远 safe
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
调整 leaderboard 生成脚本在后端不可用时的降级策略,避免生成/保留非数组 JSON 导致下游 .filter/.map 在 Next build 期间直接崩溃。
Changes:
- 将“保留既有 JSON”的条件收紧为“既有内容为数组”(非数组类型视为无效并用
[]覆盖)。 - 明确保留空数组
[](语义合法且下游不会因类型错误崩溃)。 - 更新降级分支的告警日志与注释说明,区分数组/非数组/JSON 损坏/文件不存在等场景。
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+187
to
190
| // 非数组(对象、字面量、null 等)→ 不 preserve,走下方兜底覆盖空数组 | ||
| console.warn( | ||
| `[generate-leaderboard] 后端不可用,且 ${OUTPUT} 已有内容非有效非空数组,维持原状。`, | ||
| `[generate-leaderboard] ${OUTPUT} 已存在但内容不是数组(typeof=${typeof parsed}),按无效数据处理,兜底覆盖为 []。`, | ||
| ); |
There was a problem hiding this comment.
日志里用 typeof parsed 来提示“非数组”类型时,遇到 null 会显示为 object(JS 里 typeof null === "object"),容易误导排查。建议在日志中把 null 单独显示出来(例如显示为 null),或补充更明确的类型描述。
longsizhuo
added a commit
that referenced
this pull request
Apr 27, 2026
Copilot CR (PR #328) JS 历史包袱:typeof null === "object"。之前 fallback 兜底分支日志写 "kind=object",遇到既有内容是 null 时排查者会误以为是个普通对象,绕半天。 单独识别 null,日志输出 kind=null。 实测三种情况日志输出: - null → kind=null - {...} → kind=object - "str" → kind=string Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
CR 反馈
PR #326 Copilot 指出 `scripts/generate-leaderboard.mjs:178` 的 fallback 只要 JSON.parse 成功就 `preservedExisting=true`,包括对象/null/字面量等非数组类型也会被"维持原状"。但下游 `Hero.tsx` / rank 页等多处 `import leaderboardData from "@/generated/site-leaderboard.json"` 直接 `.filter/.map`,一旦内容不是数组,整个 Next build 因 `filter is not a function` 直接挂掉。
改动
四档 fallback:
本地验证