From f4619df273892d6beaa40fc1757e6537993fd6d3 Mon Sep 17 00:00:00 2001 From: Jesse_Chen Date: Fri, 21 Aug 2026 11:03:57 +0800 Subject: [PATCH] fix(web): portal the natal board peek without effect setState Quality gate lint failed on setHeaderSlot inside useLayoutEffect, so staging never published. Pass the header mount node from a callback ref instead. Co-authored-by: Cursor --- docs/BUG_HISTORY.md | 16 ++++++++++++++++ frontend/src/app/page.tsx | 4 +++- .../conversational-birth-time-rectification.tsx | 1 + .../components/rectification-agentic-chat.tsx | 7 ++----- .../tests/rectification-agentic-entry.test.ts | 7 +++++-- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/docs/BUG_HISTORY.md b/docs/BUG_HISTORY.md index 469990ad..38f95a39 100644 --- a/docs/BUG_HISTORY.md +++ b/docs/BUG_HISTORY.md @@ -5099,6 +5099,22 @@ - 复发自:BUG-204(报告页 chunk 偏斜已修,首页引导层仍会把同一失败画成永久 loading) - 修复版本:50e1a4ac +## BUG-339 | staging quality gate 因盘面入口 effect 同步 setState 失败 + +- 状态:resolved +- 首次发现:2026-08-21 +- 最近更新:2026-08-21 +- 影响面:Gitea `backend-quality-gate` `validate`、`rectification-agentic-chat` 窄屏盘面入口 portal +- 用户现象:向 `staging` 推送后 quality gate 失败,镜像未发布,站点仍停在上一版。日志是 `react-hooks/set-state-in-effect`。 +- 触发条件:`npm run lint --prefix frontend`。自 `8b8e5214` 起,gate run 2019/2020/2021 均因此失败。 +- 根因:窄屏盘面入口用 `useLayoutEffect` 里 `querySelector` 后立刻 `setHeaderSlot`。`eslint-config-next` 禁止在 effect 同步 setState。BUG-335 把入口 portal 到页头时引入该写法。 +- 修复:页头挂载点改用 callback ref,把 DOM 节点作为 `headerSlot` 传给校时会话。仍 `createPortal` 到 `data-rectification-header-slot`,不再在 effect 里查 DOM 或 setState。 +- 验证:`frontend/tests/rectification-agentic-entry.test.ts`;`npm run lint --prefix frontend -- src/components/rectification-agentic-chat.tsx`。 +- 防复发:盘面入口不得在 effect 里 `querySelector` 后同步 setState。源码合同锁定 callback ref 与 `headerSlot` prop,并禁止 chat 内 `setHeaderSlot`。 +- 相关记录:BUG-335、BUG-334 +- 复发自:BUG-335(把入口 portal 到页头时用了 effect 同步 setState) +- 修复版本:待提交 + ## BUG-329 | 生时纠正 Agent 回答在结算后一次性出现,推理中无法停止 - 状态:resolved diff --git a/frontend/src/app/page.tsx b/frontend/src/app/page.tsx index bcae121b..c87ebd6f 100644 --- a/frontend/src/app/page.tsx +++ b/frontend/src/app/page.tsx @@ -1074,6 +1074,7 @@ export default function Home() { ); const [rectificationSessionId, setRectificationSessionId] = useState(null); const [rectificationCaseId, setRectificationCaseId] = useState(null); + const [rectificationHeaderSlot, setRectificationHeaderSlot] = useState(null); const [rectificationPendingQuestion, setRectificationPendingQuestion] = useState(null); const [rectificationLoading, setRectificationLoading] = useState(false); const [rectificationMutationPending, setRectificationMutationPending] = useState(false); @@ -3566,7 +3567,7 @@ export default function Home() { {activeSession?.title || "新对话"}
-
+