Skip to content

fix: MDX 本地图片渲染为 [object Object] + 建议接口 JSON 解析兜底 - #399

Merged
longsizhuo merged 1 commit into
mainfrom
vibe/wizardly-archimedes-j666nu
Sep 29, 2026
Merged

longsizhuo merged 1 commit into
mainfrom
vibe/wizardly-archimedes-j666nu

Conversation

@longsizhuo

Copy link
Copy Markdown
Member

背景

来自 Vercel 运行时错误巡检(过去 24h):

错误 次数
[docs/resolve] non-redirect status(大量 /docs/.../[object Object]) 94 次 / 31 个用户
/api/suggestions 解析建议 JSON 失败 5 次

改动

1. 文档本地图片全部裂图(用户可见的 bug)

remark-image 会把 [](./xxx.png) 编译成静态 import,src 是 StaticImageData 对象。mdx-components.tsx 的自定义 img 直接把对象透传给原生 <img>,结果渲染成 src="[object Object]"。浏览器按相对路径去请求 /docs/.../[object Object],这就是那 94 次 404 的主要来源。

生产环境实测:/zh/docs/learn/ai/recommender-systems/wangshusen_recommend_note/wangshusen_recommend_note_retrieval 一个页面上就有 33 张图 是 src="[object Object]"。

修复方式:对象形式的 src 取 .src,字符串形式保持不变。

2. /api/suggestions JSON 解析兜底

按生产日志里的真实失败输出逐一处理:

  • key 后面跟的是全角冒号:"action:"...
  • 冒号被包进了引号:"action:"...
  • 输出是编号列表,每行一个对象
  • 多个 [...] 数组直接拼接

把 key 后面的冒号统一成半角;整体 JSON.parse 失败时,再逐个提取 {...} 对象。5 个生产样本全部能正确解析,字符串值里本来就有的全角冒号不会被改动。

3. docs/resolve 日志降噪

后端返回 404 表示"这个路径没有历史重命名映射",是正常结论,不再用 console.error 记录。403(CF 拦截)和 5xx 仍然按错误记录,不会藏掉真正的后端故障。

验证

  • tsc --noEmit 通过
  • eslint 无新增问题;prettier 通过
  • pre-commit:vitest 89/89 通过,图片检查和 lockfile 检查通过

🤖 Generated with Claude Code

https://claude.ai/code/session_014zBGrQgQnx1eLA9jQfSJWD


Generated by Claude Code

- mdx-components: remark-image 把本地相对路径图片编译成静态 import,
  src 是 StaticImageData 对象,原生 <img> 直接透传导致 src="[object Object]",
  文档内本地图片全部裂图,并触发大量 /docs/.../[object Object] 404
- /api/suggestions: 归一化 key 后的全角冒号与缺失引号;整体 JSON.parse
  失败时逐个提取对象,兼容编号列表、多数组拼接等 LLM 输出
- docs/resolve: 后端 404(无历史映射)是正常结论,不再按 error 记录;
  403 / 5xx 仍记录

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014zBGrQgQnx1eLA9jQfSJWD
@vercel

vercel Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
involutionhell-github-io Ready Ready Preview Sep 29, 2026 12:41pm UTC
website-preview Ready Ready Preview Sep 29, 2026 12:41pm UTC

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@longsizhuo
longsizhuo merged commit 3eac782 into main Sep 29, 2026
9 checks passed

This branch was successfully deployed

2 active deployments
Preview – website-preview — e7896a66 Deployed Sep 29, 2026 by vercel[bot]
Preview – involutionhell-github-io — e7896a66 Deployed Sep 29, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants