Skip to content

refactor(chat): 把 MessageList 的行为引擎抽成模块内 hook - #531

Open
eeee0717 wants to merge 1 commit into
bench/layout-harnessfrom
refactor/message-list-hook-layers
Open

refactor(chat): 把 MessageList 的行为引擎抽成模块内 hook#531
eeee0717 wants to merge 1 commit into
bench/layout-harnessfrom
refactor/message-list-hook-layers

Conversation

@eeee0717

@eeee0717 eeee0717 commented Aug 15, 2026

Copy link
Copy Markdown
Collaborator

行为保持重构:MessageList 838 行里内联着三套彼此独立的引擎逻辑,业务接线被淹在里面。拆成三个模块私有 hook(components/hooks/,不出模块 index),MessageList 缩成 318 行接线层。

hook 职责 关键契约
useTailFollow(274 行) 尾随状态机 anchoring→following→paused + 全部交互状态 isUserInteractingRef 单一持有、对外只读——ready-gate 等其他自动滚动源必须与它守同一个「用户手上有动作时一律不滚」的不变式
useAnchorPin(297 行) 钉顶、单轮工作区首锚 staging、ready-gate 静默窗口 预留空白耗尽经 notifyAnchorSpaceClosed 把相位交接给尾随,两个 hook 不双写同一状态
useLayoutBenchInstrumentation(140 行) 探针常驻副作用(UI 线程回抛、键盘时间线、armed 同步) 信息发生在业务回调体内的调用点(anchorReady/readyGate 的 progScroll、endSpace 上报)保留裸函数留在现场

跨域组合(handleItemSizeChanged 同时触发首锚释放与尾随)留在组件当接线。被实测纠正过的长注释逐字随代码迁移。

验证

  • 传给 LegendList 的 props 逐值不变;单测断言零改动全绿(messagePresentation 10 套件 59 测试;全量 310 套件 2896 测试)。

  • bench 前后各三轮零违规feat(chat-bench): 聊天布局基准 harness——场景、相位感知判据与文档 #530 的 harness 就是本次重构的回归护栏,这是它第一次实战):

    指标 重构前 重构后
    follow-up-turn offset-reversal 17 / 17 / 24 24 / 24 / 24(阈值 100)
    estimate-collapse(三场景) 252 与 5 逐轮不变 252 与 5 逐轮不变
    send/stream offset-reversal 0-64 噪声带 0-64 噪声带,与文档确定性表逐档吻合
  • 「改了没变化」做了阳性对照:临时给 phase 探针加 v:2 字段、确认出现在设备 trace 后撤除,排除 Fast Refresh/字节码缓存假阴性(此前有两次因此得出错误结论的记录)。

🤖 Generated with Claude Code

@eeee0717
eeee0717 force-pushed the refactor/message-list-hook-layers branch from b638942 to dc28605 Compare August 15, 2026 05:16
MessageList 838 行里内联着三套彼此独立的引擎逻辑,业务接线被淹在里面。
参照「引擎与壳分离」的形状(web 端引擎在包里、RN 生态没有现成等价物,
LegendList/RNKC 都是打了 patch 才能用的,只能引擎进 hook)拆成三个模块私有
hook,MessageList 缩成 318 行接线层:

- useTailFollow:尾随状态机(anchoring→following→paused)+ 全部交互状态。
  isUserInteractingRef 由它单一持有、对外只读——ready-gate 等其他自动滚动源
  必须与它守同一个「用户手上有动作时一律不滚」的不变式。
- useAnchorPin:钉顶(handleAnchorReady)、单轮工作区首锚 staging、ready-gate
  静默窗口。预留空白耗尽时经 notifyAnchorSpaceClosed 把相位交接给尾随,
  避免两个 hook 双写同一状态。
- useLayoutBenchInstrumentation:探针常驻副作用(UI 线程回抛、键盘时间线、
  armed 同步)。信息发生在业务回调体内的调用点(anchorReady/readyGate 的
  progScroll、endSpace 上报)保留裸函数形式留在现场,搬不走。

行为保持重构:传给 LegendList 的 props 逐值不变,单测断言零改动全绿
(10 套件 59 测试);被实测纠正过的长注释逐字随代码迁移。跨域组合
(handleItemSizeChanged 同时触发首锚释放与尾随)留在组件当接线。

bench 前后各三轮零违规,关键指标同带:

  follow-up-turn offset-reversal   17/17/24 → 24/24/24(阈值 100)
  estimate-collapse                252 与 5 前后逐轮不变
  send/stream offset-reversal      0-64 区间内波动,与文档确定性表的
                                   历史噪声带逐档吻合

「改了没变化」用探针版本标记做了阳性对照(v:2 临时字段在设备 trace 出现后
撤除),排除 Fast Refresh/字节码缓存假阴性。
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