fix(web): stop rectification effects from setting state on mount
eslint-config-next failed staging lint because the case snapshot helper and choice-card reset called setState from useEffect. Load the snapshot in the fetch callback and remount the card by question id instead. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -5179,3 +5179,19 @@
|
||||
- 复发自:BUG-308(源码合同锚点过期把无关提交打红);BUG-341(第三条咨询路径与草稿变量未改合同)
|
||||
- 修复版本:6a0394aa
|
||||
|
||||
## BUG-343 | 生时纠正点选卡 effect 同步 setState,staging lint 失败
|
||||
|
||||
- 状态:resolved
|
||||
- 首次发现:2026-08-21
|
||||
- 最近更新:2026-08-21
|
||||
- 影响面:Gitea `backend-quality-gate` `validate`、`rectification-agentic-chat` 案例快照加载、`rectification-choice-card` 换题重置
|
||||
- 用户现象:BUG-342 合同修过后 `npm test` 1871/1871 通过,但 `npm run lint` 因 `react-hooks/set-state-in-effect` 失败。run `2028` `validate` 9m39s 失败,`publish` 1 秒跳过,站点仍停在 `e7f4030e`。
|
||||
- 触发条件:`npm run lint --prefix frontend`。挂载校时会话或换一道 A/B/C/D 题。
|
||||
- 根因:挂载时 `useEffect` 直接调用含 `setState` 的 `loadCaseSnapshot()`;点选卡用 effect 在 `question_id` 变化时 `setSelectedKey("")`。`eslint-config-next` 禁止 effect 同步 setState。同类于 BUG-339。
|
||||
- 修复:案例快照改为 `fetch().then` 回调里应用 payload(事件处理仍走 `loadCaseSnapshot`)。点选卡用 `key={question_id}` 换题重挂,不再在 effect 里清选中态。
|
||||
- 验证:`npm run lint --prefix frontend` 0 error;`frontend/tests/rectification-agentic-entry.test.ts`。
|
||||
- 防复发:校时 UI 不得在 effect 里直接 `setState` 或调用会 `setState` 的 helper。换题重置必须用 `key` 重挂。合同禁止 `void loadCaseSnapshot()` 和 `setSelectedKey("")`。
|
||||
- 相关记录:BUG-339、BUG-342
|
||||
- 复发自:BUG-339(盘面入口 effect 同步 setState;点选卡与快照加载又写了同一模式)
|
||||
- 修复版本:pending
|
||||
|
||||
|
||||
Reference in New Issue
Block a user