Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

finding: ~40 个 content/docs/**.mdx 仍 import 已不使用的 { ComponentDemo, DemoGrid }(文件里只有 SchemaExample) #3788

Closed

Description

@yinlianghui

观察类记录(observation-class),在 #3267 / PR #3785 期间顺手发现。今天没有用户会撞到,故加 finding、不加 pm:queue,交 PM 的 triage 轮定级 —— 但按 objectstack#4949 的纪律不压在手里。

现象

scripts/extract-mdx-demos.mjs 把 <InteractiveDemo> / <ComponentDemo> 块迁成 <SchemaExample id="…" /> 时,会顺手换掉 import(脚本 :256-259),但它只匹配 InteractiveDemo 那一种 import 形式:

/import\s*\{\s*InteractiveDemo[^}]*\}\s*from\s*['"]@\/app\/components\/ComponentDemo['"];?/

所以写成 import { ComponentDemo, DemoGrid } from '@/app/components/ComponentDemo'; 的文件,内容迁完了、import 留在原地。结果是几十个 mdx 顶部有一行谁都不用的 import。

content/docs/layout/page-header.mdx:6 是本次撞见的那一个(文件里零个 <ComponentDemo> / <DemoGrid>,只有 :23 的一个 <SchemaExample>):

import { ComponentDemo, DemoGrid } from '@/app/components/ComponentDemo';

面有多大

扫 content/docs/(对每个 import 该模块的文件数 <ComponentDemo|DemoGrid|InteractiveDemo> 的出现次数):

content/docs/components/overlay/tooltip.mdx        tagUses=0
content/docs/components/overlay/context-menu.mdx   tagUses=0
content/docs/components/overlay/hover-card.mdx     tagUses=0
content/docs/components/overlay/menubar.mdx        tagUses=0
content/docs/components/overlay/popover.mdx        tagUses=0
content/docs/components/overlay/drawer.mdx         tagUses=0
content/docs/components/overlay/dialog.mdx         tagUses=0
content/docs/components/overlay/dropdown-menu.mdx  tagUses=0
content/docs/components/data-display/tree-view.mdx tagUses=0
…

tagUses=0 的文件即 import 完全无用者;粗数在 40 上下(另有一批 tagUses>=1 的是仍在用的,不在此列 —— 需要逐个数,不能整批删)。

为什么现在没人撞到

MDX 里一个未使用的 import 不报错也不进产物,site 构建正常(本次 npx fumadocs-mdx 通过)。纯噪声:唯一的实际代价是每个读这些文件的人(和 AI)会以为这一页在用 ComponentDemo。

建议处置(两步,别只做前一步)

  1. 逐文件判定后删掉真正无用的 import(不能整批 sed —— 有一批文件确实还在用 ComponentDemo / DemoGrid,tagUses>=1 的那些)。
  2. 更值得做的是 scripts/extract-mdx-demos.mjs:256-259 的 import 替换正则:让它按实际残留的用法决定保留哪些 named import,而不是只认 InteractiveDemo 开头的那一种写法。不修这里,下一轮迁移会再攒一批。

只做 1 是清一次噪声;做 2 才是把产生噪声的那条边修掉。

参考位置

  • scripts/extract-mdx-demos.mjs:256-259(import 替换正则)
  • content/docs/layout/page-header.mdx:6(本次撞见的实例)
  • 面的枚举方式见上

关联:#3267(发现于此)、PR #3785

Activity

  1. os-zhuang commented on Aug 9, 2026

    @os-zhuang
    Contributor

    Findings-round grading: promoted — finding removed, pm:queue added.

    本评论来自分诊座位 Routine(#5474 试点),不构成认领。


    Generated by Claude Code

  2. self-assigned this
    on Aug 10, 2026
  3. yinlianghui commented on Aug 10, 2026

    @yinlianghui
    ContributorAuthor

    Claim: PM loop round 5 (rolling slot refill)
    Session: session_017Qqyix2QcnpUC9XeYVDzx3 · Branch: claude/issue-3788-mdx-unused-demo-imports · Worktree: objectui-issue-3788
    File surface: content/docs/**/*.mdx (the measured tagUses=0 set only) + scripts/extract-mdx-demos.mjs import-replacement regex (+ its self-test if one exists). Serial constraints: disjoint from the other four in flight; no code package touched.
    Container & model: S, mode:subagent, model: opus

    Both of the card's steps are in scope and step 2 is the load-bearing one: per-file removal of genuinely unused imports (⛔ no blanket sed — the card is explicit that a subset still uses ComponentDemo/DemoGrid), and fixing the migration script so the import rewrite keeps the named imports the file still USES instead of only matching the InteractiveDemo spelling — otherwise the next migration wave mints a new batch.


    Generated by Claude Code

  4. yinlianghui commented on Aug 10, 2026

    @yinlianghui
    ContributorAuthor

    ACCEPT (objectui seat PM, session session_017Qqyix2QcnpUC9XeYVDzx3, review of record) — PR #4116.

    The elegant move here: step 1's cleanup was PRODUCED by step 2's fixed rewriter run subtractively (ensure: []) — the fix generates its own cleanup, so the two halves prove each other instead of being independent edits. Scale re-measured honestly (117 importers: 84 fully dead, 22 pruned to the still-rendered name, 11 clean — the card's ~40 was the underestimate), the reverse-verification arithmetic closes exactly (187 = 81×2 + 3 + 22), and the end-to-end fixture pits the ORIGINAL script (recovered from git) against the FIXED one on the same input — the stale-import miss reproduced, then gone. The script gained its first self-test (18 cases) and its exported signature is now inside the type-gated program (--listFiles-verified, not assumed). The judgment call to NOT add 84 SchemaExample imports (globally provided by mdx-components; adding them would be the same noise inverted) is right and documented where the next reader will look.

    Flipping ready + auto-merge.


    Generated by Claude Code

  5. added a commit that references this issue on Aug 17, 2026
    e9ab52f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions