fix(app): keep a scrolled-up reader in place when they submit (#61769)

Co-authored-by: rekram1-node <63023139+rekram1-node@users.noreply.github.com>
This commit is contained in:
opencode-agent[bot]
2026-11-04 16:27:03 -06:00
committed by GitHub
Unverified
parent 36bdbb8584
commit e6338d6783
2 changed files with 75 additions and 1 deletions
@@ -560,6 +560,76 @@ for (const failed of [false, true]) {
})
}
test("keeps a reader scrolled up in place when they submit a prompt", async ({ page }) => {
await setupTimeline(page, {
reducedMotion: true,
sessionMessages: [
...validateTimelineMessages([...historyMessages(18), userMessage()]),
{ id: "msg_1002_timeline_idle", type: "idle", outcome: "succeeded", time: { created: 1700000003000 } },
],
})
const scroller = page.locator('[data-slot="session-timeline-scroll"] > [data-scrollable]')
const top = () => scroller.evaluate((element) => element.scrollTop)
const fromEnd = () => scroller.evaluate((element) => element.scrollHeight - element.clientHeight - element.scrollTop)
const jump = page.getByRole("button", { name: "Jump to latest" })
const text = "Sent while reading above."
const editor = page.locator('[data-component="composer"]').getByRole("textbox")
await expect(page.locator("[data-timeline-virtual-content]")).toHaveCSS("visibility", "visible")
await expect.poll(fromEnd).toBeLessThanOrEqual(1)
await scroller.hover()
await page.mouse.wheel(0, -1200)
await expect.poll(fromEnd).toBeGreaterThan(600)
await expect(jump).toBeInViewport()
await editor.fill(text)
const resting = await top()
const below = await fromEnd()
const requested = page.waitForRequest(
(request) => request.method() === "POST" && new URL(request.url()).pathname === `/api/session/${sessionID}/prompt`,
)
// Records the scroll position in every frame from submission until the sent prompt has grown the timeline.
const observation = await scroller.evaluateHandle((element) => {
const tops: number[] = []
let frame = 0
const sample = () => {
tops.push(element.scrollTop)
frame = requestAnimationFrame(sample)
}
frame = requestAnimationFrame(sample)
return {
stop: () => {
cancelAnimationFrame(frame)
return tops
},
}
})
try {
await editor.press("Enter")
expect((await requested).postDataJSON()).toMatchObject({ text })
await expect(editor).toHaveText("")
// The sent prompt lands below the reader, so the distance to the end grows while the reader stays put.
await expect.poll(fromEnd).toBeGreaterThan(below)
const tops = await observation.evaluate((value) => value.stop())
expect(tops.length).toBeGreaterThan(0)
expect(tops.every((value) => Math.abs(value - resting) <= 1)).toBe(true)
expect(Math.abs((await top()) - resting)).toBeLessThanOrEqual(1)
await expect(jump).toBeInViewport()
} finally {
await observation.dispose()
}
await jump.click()
await expect(page.locator('[data-timeline-row="UserMessage"]').filter({ hasText: text })).toBeInViewport()
await expect.poll(fromEnd).toBeLessThanOrEqual(1)
})
async function captureCardEdges(page: Page, card: Locator) {
const box = await card.boundingBox()
+5 -1
View File
@@ -332,7 +332,11 @@ export function createActiveSessionRegion(input: {
state,
parentID: input.session.data.parentID,
centered: input.screen.centered,
onResponseSubmit: input.timeline.actions.resume,
// Submitting keeps following only when already following. A reader scrolled up stays where they are; the
// jump-to-latest button takes them down.
onResponseSubmit: () => {
if (input.timeline.view.pinned()) input.timeline.actions.resume()
},
openParent,
focusPrompt: () => focusPrompt(),
setPromptRef: (element: HTMLDivElement) => {