Repository navigation
fix(app): keep the transcript pinned to the bottom when WebKit clamps the scroll position - #5390
Conversation
… the scroll position
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e24030f42b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
commit: |
… the scroll position (#5390) * fix(app): keep the transcript pinned to the bottom when WebKit clamps the scroll position * chore: drop changesets for the transcript scroll fix --------- Co-authored-by: liruifengv <[email protected]>
… the scroll position (#5390) * fix(app): keep the transcript pinned to the bottom when WebKit clamps the scroll position * chore: drop changesets for the transcript scroll fix --------- Co-authored-by: liruifengv <[email protected]>
Requirement or Bug
在 iOS(Safari、iOS Chrome,都是 WebKit 内核)上通过 Web 或 Remote Control 打开会话,常常停在会话中间,而不是最底部;点了「最新消息」回到底部后,流式回复过一会儿又不再跟随。这个 PR 修好后,打开会话会停在底部,流式回复期间保持跟随。
Bug Reproduction Steps
kimi web/ Remote Control 页面。Playwright 的 WebKit 加手机视口也能稳定复现;Chromium 不复现。
Root Cause
Markdown 渲染器在重新渲染最后一行时,会先卸载再挂回代码块等节点。两步之间有代码强制触发了一次布局,所以内容会短暂变矮。WebKit 会立刻把
scrollTop截断到这时更小的最大值;Chromium 会推迟这种截断,所以不受影响。内容在同一个任务里又长回原高度,scrollHeight恢复了,scrollTop却停在被截断后的位置。滚动控制器随后在
scroll事件或 resize 回调的correct()里看到位置意外上移、离底部超过阈值,就把它当成用户上滑,退出 follow 进入 anchored。于是页面停在中间,后续流式内容也不再跟随。sequenceDiagram participant R as 渲染器(同一任务内) participant W as WebKit participant C as 滚动控制器 R->>R: 卸载代码块 R->>W: 强制布局 W->>W: 内容变矮,scrollTop 被截断 R->>R: 挂回代码块,内容恢复原高 W-->>C: scroll 事件 / resize 回调里的 correct() C->>C: 改动前:判定为用户上滑,退出 follow C->>C: 改动后:判定为截断,写回底部这是根本修复:控制器能分辨这种并非用户造成的截断,不依赖渲染器的具体行为。
真机日志还暴露了两个时序细节,都在这次一起处理:
correct()可能发生在同一次 Vue 更新里,这时 MutationObserver 回调还没执行。Code Changes
核心思路: 在 follow 模式下,满足三个条件的向上位移按截断处理,直接写回底部、保持 follow:
内容变化来自滚动容器子树上的 MutationObserver。判断时先用
takeRecords()同步读取还没投递的记录,再看「两帧内有过变化」的标记。只有确实没有内容变化时,意外滚动才像以前一样视为用户滚动。handleScroll(layout) if top < expected && (top at max || layout follow clamp ≤ 80px) adopt + if follow && top < expected && no wheel/key/touch/drag/press in flight + && (pending mutation records || mutated within the last two frames) + adopt top, write bottom, stay in follow ... treat as user scroll → anchored此外还有两处输入判定上的补充:
press意图。按住期间的滚动(比如拖选文字触发的自动滚动)仍算用户操作,会正常退出 follow。中键自动滚动在松开后还会继续,所以中键按下保持 sticky,直到下一次按下或回到底部才清除。touchend/touchcancel现在也监听在 touchstart 的目标元素上。流式渲染替换了手指下的节点后,touchend不会再冒泡到滚动容器,旧代码里touching会一直为 true,控制器从此不再写滚动位置。阅读指南
packages/app-core/src/lib/transcriptScroll/scrollController.ts:contentClamp、onMutation、followTouchTarget,以及press/drag-end分支。packages/app-core/src/lib/transcriptScroll/intent.ts:pointerdown新增press意图。packages/app-core/test/transcriptScroll/layoutSim.ts:模拟器新增假的 MutationObserver,包括takeRecords和mutate/queueMutation,以及帧内取消回调的语义。Behavior Changes and Affected Users
Cmd/Ctrl+F打开的是应用内搜索,不受影响;Desktop 应用的对话页没有原生查找Cmd/Ctrl+F),或等流式结束后再用浏览器查找readScrollIntent对非滚动条位置的主键或中键pointerdownnull{ kind: 'press', sticky }touching卡住,follow 不再写位置受影响的界面是 Desktop 和 Web(含
kimi web、Remote Control)的对话滚动,WebKit 内核受影响最明显。Chromium 和 Electron 上不会出现这种截断,新分支基本不会被触发。测试覆盖与验证
scrollController.test.ts新增以下用例,去掉对应修复都会失败:intent.test.ts:按设计改了原断言,非滚动条主键或中键按下由null变为press。pnpm exec vitest run --reporter=agent packages/app-core/test/transcriptScroll:118 passed。pnpm lint:通过。pnpm --filter kimi-code-app run typecheck:通过。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.(按维护者决定,本 PR 不带 changeset)gen-docsskill, or this PR needs no doc update.