Skip to content

chore(frontend): remove 6 unmounted components + 3 orphaned CSS modules - #234

Open
flyhigher139 wants to merge 1 commit into
masterfrom
chore/remove-dead-components
Open

flyhigher139 wants to merge 1 commit into
masterfrom
chore/remove-dead-components

Conversation

@flyhigher139

Copy link
Copy Markdown
Contributor

背景

昨天(2026-09-28)的性能复审开了 #224–#230 共 7 个 issue。复核其中 #230 第 4 项(P-F7) 时发现它指向的代码从未被挂载,因此这个 PR 不是「修 bug」,而是删死代码 + 把该 issue 重新定性。

P-F7 的实际状态

src/pages/ProfileEdit.tsx 自 commit 1bfe932(#55 sidebar/drawer UI 重构)起就没有任何引用——无路由、无 import、无测试、无动态 import。

Issue 原文把它描述为「用户未保存的 name/description 编辑可能丢失」,并建议优先于 #230 其余各项处理。实际情况:

组件 状态 P-F7 是否存在
pages/ProfileEdit.tsx 死代码(#55 后解绑) 是,但跑不到
components/HostsProfileView.tsx 活 否
components/DnsProfileView.tsx 活 否

活代码本来就已经免疫:

  • HostsProfileView.tsx:100-113 — 播种 effect 依赖已是 [profile?.id],不是 [profile]
  • HostsProfileView.tsx:155-166 — draftInfo 在用户点「编辑」时按需播种,不经过 effect
  • DnsProfileView.tsx — 全文 0 个 useEffect

所以不存在用户数据丢失。此前的优先级判断(建议它插队先合)建立在错误前提上,在此更正。

根因:审计流程缺口,不是代码缺陷

#90 复审与本次 2026-09-28 复审都是按文件扫描而非按可达性扫描,于是连续两轮在从不运行的代码上「发现」了问题:

删代码比逐个修补这些幻影更彻底。

变更内容

删除 6 个组件:

文件 行数 原因
pages/ProfileEdit.tsx 176 1bfe932 (#55) 后解绑
components/BasicInfoForm.tsx 58 唯一 importer 是 ProfileEdit,随之暴露
components/RuleList.tsx 56 仅为 import ProfileEdit 的 CSS 而存在
components/ProfileCard.tsx 119 已被 DrawerProfileCard 取代
components/CreateProfileForm.tsx 53 从未挂载
components/ApplyStatus.tsx 141 从未挂载(#230 第 7 项)

删除 283 行测死代码的测试 —— 这是 ApplyStatus.tsx 长期「看起来还在维护」的原因:它有测试,但那个测试从不参与真实渲染。

删除 3 个随之孤立的 CSS module: ProfileEdit.module.css、ProfileList.module.css、ApplyStatus.module.css。

保留全局 .toggle / .toggle-slider:注释原写「used by ProfileCard」,但实际消费者是 pages/AdBlock.tsx(:326 / :597 / :790),只更正注释。

净:12 files changed, +2 / −1309。

验证

  • pnpm test — 26 files / 353 tests 全绿
  • pnpm build(tsc && vite build)— 无悬空 import,构建通过
  • 重新扫描 src/pages + src/components:无未挂载组件残留
  • 未触碰任何 Rust 代码

回滚

若日后要恢复独立编辑页,git revert 本 PR 的单个提交即可完整取回(含 CSS 与测试)。判断依据已写在 commit message 中:零引用、零测试、编辑能力已被 HostsProfileView / DnsProfileView 完整覆盖、且是被一次显式重构解绑而非意外遗漏。

关联

覆盖 #230 第 4、7 项。第 4 项将以「指向死代码,已随删除消解」重新定性,不再作为 perf 项排期。

🤖 Generated with Claude Code

Deleting -1309 lines of code that no route or component can reach.

#230 item 7 (P-F6, ApplyStatus) already proposed this. Items 4 and the
underlying finding are broader than that, and both need reclassifying:

- Item 4 (P-F7) claimed ProfileEdit "silently discards unsaved
  name/description edits" and asked for it to outrank the rest of the
  perf batch. ProfileEdit has had zero importers since 1bfe932 (the #55
  sidebar/drawer redesign) — no route, no import, no test, no dynamic
  import. The live editing components are not affected: HostsProfileView
  already seeds draft rules on `[profile?.id]` (not `[profile]`) and
  seeds draftInfo on-demand in handleEditInfo rather than in an effect,
  and DnsProfileView has no useEffect at all. There was no user-facing
  data loss to fix.

The underlying cause is an audit-process gap, not a code defect: both
the #90 review and the 2026-09-28 review scanned files rather than
reachability, so each produced findings against code that never runs.
Deleting the code removes the false positives rather than patching them.

Removed:
  pages/ProfileEdit.tsx          orphaned by 1bfe932 (#55 redesign)
  components/BasicInfoForm.tsx   only importer was ProfileEdit
  components/RuleList.tsx        existed only to import ProfileEdit's CSS
  components/ProfileCard.tsx     superseded by DrawerProfileCard
  components/CreateProfileForm.tsx
  components/ApplyStatus.tsx     unmounted; see #230 item 7
  __tests__/ApplyStatus.test.tsx 283 lines covering a never-rendered
                                 component, which is why the dead
                                 component kept looking maintained

CSS modules orphaned by the above:
  pages/ProfileEdit.module.css   only ProfileEdit + RuleList
  pages/ProfileList.module.css   only ProfileCard + CreateProfileForm
  components/ApplyStatus.module.css

Not removed: the global `.toggle` / `.toggle-slider` classes. The comment
credited ProfileCard, but AdBlock is the live consumer (pages/AdBlock.tsx
:326, :597, :790), so only the comment is corrected.

Verification: pnpm test 353 passed / 26 files, pnpm build (tsc + vite)
clean. No Rust touched.
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.

1 participant