Repository navigation
Description
English
What happened
After scrolling to the bottom of a long Desktop conversation containing Mermaid diagrams, the visible transcript keeps jumping vertically without further input. In the original recording, the timeline and following text repeatedly move by 89px. Away from the bottom, leaving the timeline near the viewport's lower edge triggers persistent scrollbar oscillation; compensation generally preserves the visible content position.
Expected: the transcript and scrollbar settle when scrolling stops, including at the conversation bottom.
How to reproduce
- Open a long conversation with Mermaid diagrams in consecutive replies. The verified conversation has a pie diagram in the first reply and a timeline in the second.
- Scroll all the way to the transcript bottom.
- Stop scrolling and leave input devices untouched for at least 10 seconds.
- Observe the timeline and following text repeatedly jumping vertically.
- Scroll upward until the timeline sits near the bottom of the viewport, then stop input again.
- Observe the right vertical scrollbar continuing to oscillate.
This describes the verified conversation, not a standalone minimal reproduction. Not every diagram position or viewport triggers the loop.
Original environment and recordings
- Maka:
upstream/main,ab5996bdbe125f85ec86a0b3d54a6738c16e7af8. - Desktop UI, macOS; Electron 43.4.1 / Chromium 150.0.7871.224.
- Astryx 0.6.3; virtua 0.52.7; replay viewport 1240×700.
Both original 10-second recordings use upstream ChatView, MermaidDiagram, scroll authority, and renderer CSS with real conversation data. They are isolated Electron UI replays, not full installed-app recordings. No scroll input occurs during capture; overlays display live measurements.
At the conversation bottom:
reproduction.webm
| Measurement | Repeated states |
|---|---|
| Timeline viewport top | -27.97 ↔ 61.03px |
| scrollTop | 3649 / 3372 / 3560 |
| scrollHeight | 4349 ↔ 4072 |
| Visible timeline viewport height | 385px, unchanged |
The 89px jump repeats approximately every 0.23 seconds throughout the original capture.
Away from the conversation bottom:
reproduction.webm
| Measurement | Repeated states |
|---|---|
| scrollTop | 3275 ↔ 2998 |
| scrollHeight | 4349 ↔ 4072 |
| Transcript clientWidth | 1229px, unchanged |
| Visible timeline viewport height | 385px, unchanged |
The scrollbar oscillates approximately every 200ms. Compensation generally keeps the visible timeline position stable.
Root cause and chosen correction
The root is MermaidDiagram's temporary remount geometry. Even with a warm render-template cache, the original component commits loading, rendered/measuring at natural dimensions, and rendered/ready after JS clamps the height. A previously measured virtual row therefore returns with a different height.
virtua's direction-dependent buffer amplifies this instability: idle restores backward rows → the pie remounts and changes height → compensation or following the tail writes the scroll position → downward direction removes the backward buffer → the pie unmounts → idle restores it again. At the tail, compensation and tail-following can expose content jumps; away from the tail, the scrollbar still oscillates.
The selected fix in draft PR #5962 changes MermaidDiagram rather than the virtualizer:
- Restore warm cached templates synchronously during initial state creation, skipping loading on remount.
- Compute fitted dimensions in CSS from SVG ratio, container width, viewport height limit, and zoom. Remove viewportLayout and the asynchronous measuring stage.
- Keep one component and identify its rendered source/theme with cacheKey. Retain independent SVG IDs, LRU recency, and an observer that updates panning affordances without setting dimensions.
No bidirectional-buffer patch, keepMounted exception, scroll-authority change, or cache-capacity change is included. The earlier control that retained both buffers stopped the symptoms, but did not establish stable remount geometry. Disabling the top fade did not stop the loop.
Verification and remaining boundaries
Local ablation distinguishes idle stability from first-commit geometry:
| Variant | Warm-remount first commit → final height |
|---|---|
| Selected simplified fix | rendered 462→462px |
| No synchronous cache restoration | loading 145→462px |
| Synchronous restoration with old JS sizing | rendered 551→462px |
CSS alone also stopped the observed idle loop but retained the loading transition. This supports the chosen warm-remount geometry guarantee; it does not prove both changes are individually necessary for every idle loop.
New 10-second side-by-side replays compared baseline 7c90bac2d with the final fix at 1240×700. The baseline oscillated at both positions. The fix stayed at scrollTop/scrollHeight 3649/4349 at the tail and 2996/4349 at the reading position across all 578 and 577 samples, respectively. These were isolated production UI replays, not installed-app verification. Related local tests: 106 passed.
The submitted regression checks cached-remount React commits. CSS geometry currently relies on local browser measurements and recordings, without a new automated geometry CI gate. Cold cache misses and source/theme changes of an already-mounted component retain their asynchronous paths; the guarantee applies to warm remounts. The fix is committed in the draft PR, not merged or released.
Pending manual checks: the original conversation in the installed Desktop app at both positions, light/dark theme switching, zoomed panning, fullscreen entry/exit, and 1.25 zoom with always-visible scrollbars on macOS or Windows where available.
AI assistance and review
OpenAI Codex assisted with diagnosis, implementation, ablation, and this report under user direction. The reporter reviewed the original report and recordings before submission; the user subsequently approved the Mermaid-owned correction and requested this update. PR #5962 records verification and deferred review findings.
中文
发生了什么
在包含 Mermaid 图表的桌面端长会话中,滚动到正文末尾后,即使停止输入,可见正文仍持续上下跳动。原始录屏中,时间线图和后续文字反复移动 89px。未到底部时,让时间线图停留在视口下缘附近,会触发滚动条持续抖动;此时补偿通常保持可见正文的位置。
预期:停止滚动后,正文和滚动条应稳定下来,包括会话底部。
如何复现
- 打开一个连续两轮回复包含 Mermaid 图表的长会话。已验证会话的第一轮有饼图,第二轮有时间线图。
- 滚动到正文末尾。
- 停止滚动,至少 10 秒内不操作输入设备。
- 观察时间线图和后续正文反复上下跳动。
- 向上滚动,让时间线图停在视口底部附近,再停止输入。
- 观察右侧纵向滚动条持续抖动。
这是已验证会话的复现条件,不是独立最小复现。并非所有图表位置或视口都会触发循环。
原始环境与录屏
- Maka:
upstream/main,ab5996bdbe125f85ec86a0b3d54a6738c16e7af8。 - 桌面端 UI,macOS;Electron 43.4.1 / Chromium 150.0.7871.224。
- Astryx 0.6.3;virtua 0.52.7;回放视口 1240×700。
原始两段 10 秒录屏使用上游 ChatView、MermaidDiagram、滚动权威和渲染 CSS,回放真实会话数据。它们是隔离 Electron UI 回放,不是完整安装版应用录屏。录制期间没有滚动输入;叠加面板展示实时测量。
正文底部:
reproduction.webm
| 测量项 | 反复出现的状态 |
|---|---|
| 时间线图视口顶部 | -27.97 ↔ 61.03px |
| scrollTop | 3649 / 3372 / 3560 |
| scrollHeight | 4349 ↔ 4072 |
| 可见时间线图视口高度 | 385px,保持不变 |
原始录屏全程约每 0.23 秒重复一次 89px 跳动。
未到正文底部:
reproduction.webm
| 测量项 | 反复出现的状态 |
|---|---|
| scrollTop | 3275 ↔ 2998 |
| scrollHeight | 4349 ↔ 4072 |
| 正文 clientWidth | 1229px,保持不变 |
| 可见时间线图视口高度 | 385px,保持不变 |
滚动条约每 200ms 抖动一次;补偿通常保持当前时间线图的位置。
根因与最终采用的修正
根因是 MermaidDiagram 重新挂载时的临时几何。即使渲染模板缓存已命中,原组件仍会依次提交加载占位、按自然尺寸铺开的 rendered/measuring、以及 JS 夹紧高度后的 rendered/ready。因此,已测量的虚拟行重新出现时,高度与缓存值不一致。
virtua 按滚动方向变化的缓冲区放大了这种不稳定:空闲恢复前方行 → 饼图重新挂载并改变高度 → 补偿或跟随底部写入滚动位置 → 向下方向撤掉前方缓冲 → 饼图卸载 → 下一次空闲再次恢复。在底部,补偿和跟随底部可能使正文跳动;离开底部,滚动条仍会抖动。
草稿 PR #5962 采用的修复位于 MermaidDiagram:
- 初始 state 同步恢复暖缓存模板,重挂载时跳过加载占位。
- 根据 SVG 比例、容器宽度、视口高度上限和缩放,在 CSS 中计算适配尺寸,删除 viewportLayout 和异步测量阶段。
- 保持单个组件,通过渲染结果的 cacheKey 识别源码与主题。保留独立 SVG ID、LRU 使用顺序更新,以及只更新平移提示、不设置尺寸的观察器。
没有加入双向缓冲补丁、keepMounted 特例,也没有改滚动权威或缓存容量。此前保留双向缓冲的对照能停止症状,但未解决重挂载几何稳定性。关闭顶部渐隐不能停止循环。
验证与剩余边界
本地消融区分了空闲稳定性与首次提交几何:
| 变体 | 暖缓存重挂载首次提交 → 最终高度 |
|---|---|
| 最终简化方案 | rendered 462→462px |
| 去掉同步缓存恢复 | loading 145→462px |
| 同步恢复但使用旧 JS 测量 | rendered 551→462px |
仅修改 CSS 也能停止实验中的空闲循环,但仍有加载占位。这支持最终采用的暖缓存重挂载几何保证,不代表两项改动分别对所有空闲循环都必不可少。
新的两段 10 秒同屏回放在 1240×700 下对比基线 7c90bac2d 与最终修复。基线在两个位置均振荡;修复在底部的 578 次采样中始终为 scrollTop/scrollHeight 3649/4349,在阅读位置的 577 次采样中始终为 2996/4349。这些是隔离生产 UI 回放,不是安装版应用验收。相关本地测试共 106 项通过。
提交的回归测试检查暖缓存重挂载的 React 提交。CSS 几何目前依靠本地浏览器测量和录屏,没有新增自动几何 CI 闸门。冷缓存未命中,以及已挂载组件的源码/主题变化,仍保留异步路径;首帧保证针对暖缓存重挂载。修复已提交到草稿 PR,尚未合并或发布。
待人工检查:安装版 Desktop 中原会话的两个位置、浅色/深色主题切换、缩放后平移、全屏进入与退出,以及条件允许时在 macOS 或 Windows 常驻滚动条模式下的 1.25 倍缩放。
AI 辅助与审阅
OpenAI Codex 在用户指导下辅助诊断、实现、消融和报告编写。报告人提交前审阅了原始报告和录屏;用户随后认可 Mermaid 组件内的修正方案,并要求更新本说明。PR #5962 记录验证结果和延期的审查意见。
Activity
[-]Desktop transcript keeps flickering after scrolling stops near a Mermaid diagram[/-][+]fix(desktop): stop Mermaid chat flicker at bottom[/+]