refactor(chat): 把 MessageList 的行为引擎抽成模块内 hook - #531
Open
eeee0717 wants to merge 1 commit into
Open
Conversation
eeee0717
force-pushed
the
refactor/message-list-hook-layers
branch
from
August 15, 2026 05:16
b638942 to
dc28605
Compare
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/字节码缓存假阴性。
eeee0717
force-pushed
the
refactor/message-list-hook-layers
branch
from
August 15, 2026 08:30
dc28605 to
cbc5e04
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
行为保持重构:MessageList 838 行里内联着三套彼此独立的引擎逻辑,业务接线被淹在里面。拆成三个模块私有 hook(
components/hooks/,不出模块 index),MessageList 缩成 318 行接线层。useTailFollow(274 行)isUserInteractingRef单一持有、对外只读——ready-gate 等其他自动滚动源必须与它守同一个「用户手上有动作时一律不滚」的不变式useAnchorPin(297 行)notifyAnchorSpaceClosed把相位交接给尾随,两个 hook 不双写同一状态useLayoutBenchInstrumentation(140 行)跨域组合(
handleItemSizeChanged同时触发首锚释放与尾随)留在组件当接线。被实测纠正过的长注释逐字随代码迁移。验证
传给 LegendList 的 props 逐值不变;单测断言零改动全绿(messagePresentation 10 套件 59 测试;全量 310 套件 2896 测试)。
bench 前后各三轮零违规(feat(chat-bench): 聊天布局基准 harness——场景、相位感知判据与文档 #530 的 harness 就是本次重构的回归护栏,这是它第一次实战):
「改了没变化」做了阳性对照:临时给 phase 探针加
v:2字段、确认出现在设备 trace 后撤除,排除 Fast Refresh/字节码缓存假阴性(此前有两次因此得出错误结论的记录)。🤖 Generated with Claude Code