fix(report): defer lazy-section setState so staging lint can pass

IntersectionObserver fallback called setVisible inside useEffect, which the
react-hooks compiler treats as an error. Queue it on rAF so the gate can
publish the MD report page.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Jesse_Chen
2026-09-06 22:33:38 +08:00
co-authored by Cursor
parent 809bdf13e9
commit ebc8380fb8
4 changed files with 30 additions and 8 deletions
+16
View File
@@ -8661,4 +8661,20 @@
- 复发自:无
- 修复版本:`cfcd369d`
## BUG-563 | 报告 MD 详情页在无 IntersectionObserver 时同步 setState,staging 门禁 lint 失败
- 状态:resolved
- 首次发现:2026-09-06
- 最近更新:2026-09-06
- 影响面:`frontend/src/components/personal-report/personal-report-markdown-view.tsx`、Gitea `backend-quality-gate` run 2446
- 用户现象:staging 未部署本轮报告 MD 页;门禁 `npm run lint` 1 error 后 `publish`/`deploy-staging` 未跑。站点 `/api/health` 的 `deployment.gitCommit` 仍停在此前 SHA。
- 触发条件:`LazyMarkdownSection` 在 `IntersectionObserver` 未定义时(SSR / 部分测试环境)于 `useEffect` 内同步 `setVisible(true)`。
- 根因:react-hooks 编译器规则禁止 effect 内同步 setState,以免级联渲染。仓库红线是 lint 0 error。
- 修复:无观察器时改为 `requestAnimationFrame` 后再 `setVisible`,并在清理函数里 `cancelAnimationFrame`。SSR 首屏仍只渲染 eager 段。
- 验证:`npm run lint -- src/components/personal-report/personal-report-markdown-view.tsx` 0 error;`frontend/tests/personal-report-markdown-view.test.ts` 仍断言懒加载段不进 SSR 标记。
- 防复发:报告 MD 视图 effect 不得同步 setState;后续 lint 0 error 才允许合入 staging。
- 相关记录:BUG-561、BUG-562
- 复发自:无
- 修复版本:待本提交 SHA