Files
labelmain-demo/.react-doctor/false-positives.md
zhangheng dbd01ee15b docs: record react-doctor false positives
Log confirmed false positives for server-auth-actions (genAccessToken,
the session-validation endpoint itself) and exhaustive-deps (intentional
minimal-deps effects where adding deps would cause re-render loops) so
future triage skips them.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-05 11:18:46 +08:00

2.6 KiB

React Doctor — 已确认的误报 (false positives)

本文件记录经人工确认的误报。React Doctor 在分诊时会读取此文件并跳过匹配的诊断。 每条注明:规则、位置、代码形状、为何是误报。


react-doctor/server-auth-actions

  • 位置: components/login/libs/session.tsgenAccessToken
  • 代码形状: 文件顶部含 "use server",导出的 async 函数本身就是会话校验 / 凭证建立端点——读取会话 cookie (SESSION_COOKIE_NAME)、查 redis、校验客户端 IP,失败时返回 ok:false 重定向到登录页。
  • 为何是误报: 该函数就是鉴权逻辑本身,不存在"调用前的会话"可供校验。规则的 validation prompt 明确把"action 即认证/凭证建立端点(login/signup/OTP/session 校验)"列为典型误报——这里因函数名为 genAccessToken(不在规则的 auth()/validateSession() 等识别名单内)而误触发。给它再加 auth() 会构成循环逻辑。
  • 判定: 跳过此规则在该函数上的诊断。

react-doctor/exhaustive-deps — 有意排除的依赖(加了会引 bug)

以下 useEffect 均有意保持最小依赖数组,且都已带 // eslint-disable-next-line react-hooks/exhaustive-deps(react-doctor 用的是 oxlint 同名规则,故未被该注释覆盖)。逐条确认:补齐缺失依赖会引入真实 bug,故不改逻辑,登记为误报。

  • app/person/report/components/DailyReportModal.tsx:190 — 缺 resetFormState 等。resetFormState 每次渲染重建,加入依赖会导致 effect 每次渲染都执行(反复重置表单)。effect 设计为仅在 [opened, record, user_name] 变化时运行。

  • app/person/report/components/DailyReportModal.tsx:201 / :227 — 缺 form.setFieldValue。Mantine form 方法引用稳定;effect 有意仅在对应 form.values.* 变化时联动计算字段,补 setter 无意义且违背设计意图。

  • app/person/workload/WorkloadMetricsTable.tsx:124 — 缺 refresh。这是 [] 挂载时一次性拉取数据的 effect;refresh 为每次渲染重建的普通 async 函数,加入依赖会导致每次渲染重复请求。

  • components/tree-select/tree.tsx:122 — 缺 tree.initializeuseTree() 每次渲染返回新的 controller 对象(文件内注释亦说明此点),依赖它会造成无限重渲染;effect 有意仅在 [data] 变化时初始化。

  • 判定: 以上位置跳过 exhaustive-deps。如需让 react-doctor 扫描层面也静默,可在各行改用 // oxlint-disable-next-line react-doctor/exhaustive-deps 并附理由(本表已记录理由)。