Skip to content

fix(desktop): follow streaming output when user is at bottom (#2159)#2235

Merged
esengine merged 1 commit into
esengine:mainfrom
nianyi778:fix/desktop-auto-scroll-streaming
May 29, 2026
Merged

fix(desktop): follow streaming output when user is at bottom (#2159)#2235
esengine merged 1 commit into
esengine:mainfrom
nianyi778:fix/desktop-auto-scroll-streaming

Conversation

@nianyi778

Copy link
Copy Markdown

问题

关闭 #2159。桌面版流式输出时不自动滚动到底部。

根因

useEffect 没有依赖数组(每次渲染都执行),但没有检查 atBottomRef.current

// 旧代码:无依赖数组 → 每次渲染执行,且不检查用户是否在底部
useEffect(() => {
  const s = virtScrollerRef.current;
  if (!s || messageItems.length === 0) return;
  const id = requestAnimationFrame(() => { s.scrollTop = s.scrollHeight; });
  return () => cancelAnimationFrame(id);
});

问题:

  1. 无依赖数组 → React 在高频 re-render 时可能跳过某些效果的执行
  2. 不检查 atBottomRef.current → 用户向上滚动查看历史时也会被强制拉回底部

修复

添加 [messageItems] 依赖数组 + atBottomRef.current 检查:只有新消息到来且用户在底部时才滚动。

…e#2159)

The scroll-follow useEffect had no dependency array, so it ran on every
render but did not check atBottomRef — meaning it would try to re-pin
even when the user had scrolled up to read earlier content, and conversely
the missing dep array caused React to skip the effect in some batched
renders during fast streaming.

Add a guard on atBottomRef.current and a proper [messageItems] dependency
so the effect only fires when new messages arrive and only scrolls when
the user is already pinned to the bottom.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@nianyi778

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@esengine esengine left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct fix for #2159. The auto-scroll effect now guards on atBottomRef.current (don't re-pin to bottom when the user has scrolled up to read history) with a re-check inside the rAF, and gains a [messageItems] dep so it stops firing on every render. Follows streaming output when the user is at the bottom, leaves them alone when they're not. Small and right, CI green. Merging.

@esengine esengine merged commit 893c1c7 into esengine:main May 29, 2026
4 checks passed
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.

2 participants