fix(app): polish the jump-to-latest button (#56684)

This commit is contained in:
Kit Langton
2026-10-17 22:21:40 -07:00
committed by GitHub
Unverified
parent 07b53425c7
commit e1aad7db4b
6 changed files with 61 additions and 22 deletions
@@ -381,9 +381,10 @@ test("jump to latest lands on stable final rows after offscreen growth", async (
})
const scroller = page.locator(".scroll-view__viewport", { has: page.locator("[data-timeline-row]") })
await scroller.evaluate(
(element) => (element.scrollTop = Math.max(0, element.scrollHeight - element.clientHeight - 600)),
)
await scroller.evaluate((element) => {
element.dispatchEvent(new WheelEvent("wheel", { bubbles: true, deltaY: -1 }))
element.scrollTop = 0
})
await timeline.send(partUpdated(shell(shellID, "running", lines(50))), 300)
const regions = defineVisualRegions({
@@ -562,7 +562,11 @@ for (const device of ["Pixel 7", "iPhone 13"]) {
if (!handoff.held) await devtools.send("Input.dispatchTouchEvent", { type: "touchEnd", touchPoints: [] })
if (handoff.key === "latest") await latest.click()
if (handoff.key === "latest") {
await latest.click()
// The hidden button no longer covers the timeline, so a resting pointer would hover it and keep the thumb shown.
await page.mouse.move(0, 0)
}
if (handoff.key !== "latest" && !usesScrollbar) await scroller.press(handoff.key)
@@ -38,6 +38,30 @@ test("space activates a focused timeline button instead of scrolling", async ({
expect(await scroller.evaluate((element) => element.scrollTop)).toBe(before)
})
test("jump to latest is reachable only while it is shown", async ({ page }) => {
await setupTimeline(page, {
messages: [userMessage(), assistantMessage([textPart("prt_jump_latest_text", "Latest response.")])],
seedHistory: true,
})
const scroller = page.locator(".scroll-view__viewport", { has: page.locator("[data-timeline-row]") })
const jump = page.getByRole("button", { name: "Jump to latest", exact: true })
const latest = page.getByText("Latest response.", { exact: true })
await expect(latest).toBeInViewport()
await jump.focus()
await expect(jump).not.toBeFocused()
await scroller.hover()
await page.mouse.wheel(0, -3000)
await expect(latest).not.toBeInViewport()
await jump.click()
await expect
.poll(() => scroller.evaluate((element) => element.scrollHeight - element.clientHeight - element.scrollTop))
.toBeLessThanOrEqual(1)
await expect(latest).toBeInViewport()
// The click focused the button; hiding it must not leave focus on an invisible control.
await expect(jump).not.toBeFocused()
})
function lines(count: number) {
return Array.from({ length: count }, (_, index) => `line ${index + 1}`).join("\n")
}
@@ -59,7 +59,7 @@ export function createSessionTimelineInteraction(session: SessionModel) {
// The active timeline's navigation, registered by its virtualizer.
let revealMessage = (_id: string, _partID?: string) => {}
let scrollToEnd = () => {}
let scrollToEnd = (_behavior?: ScrollBehavior) => {}
let scrollMark = 0
let messageMark = 0
@@ -160,10 +160,10 @@ export function createSessionTimelineInteraction(session: SessionModel) {
consumePendingMessage: (key) => layout.pendingMessage.consume(key),
})
const resume = () => {
const resume = (behavior?: ScrollBehavior) => {
setState("messageID", undefined)
pin()
scrollToEnd()
scrollToEnd(behavior)
clearMessageHash()
if (scroller) scheduleScrollState(scroller)
@@ -397,7 +397,7 @@ export function createSessionTimelineInteraction(session: SessionModel) {
},
},
setScrollRef,
setScrollToEnd: (scroll: () => void) => {
setScrollToEnd: (scroll: (behavior?: ScrollBehavior) => void) => {
scrollToEnd = scroll
},
unpin,
@@ -73,7 +73,7 @@ type MessageTimelineProps = {
background: SessionBackground
actions?: SessionUserActions
scroll: { overflow: boolean; jump: boolean }
onResumeScroll: () => void
onResumeScroll: (behavior?: ScrollBehavior) => void
setScrollRef: (el: HTMLDivElement | undefined) => void
onScheduleScrollState: (el: HTMLDivElement) => void
onPin: () => void
@@ -87,7 +87,7 @@ type MessageTimelineProps = {
setContentRef: (el: HTMLDivElement) => void
anchor: (id: string) => string
setRevealMessage?: (fn: (id: string, partID?: string) => void) => void
setScrollToEnd?: (fn: () => void) => void
setScrollToEnd?: (fn: (behavior?: ScrollBehavior) => void) => void
reveal?: { target: () => string | undefined; done: () => void }
search?: JSX.Element
}
@@ -63,7 +63,7 @@ type Input = {
/** True while the timeline follows the newest content. Drives every anchoring decision. */
pinned: Accessor<boolean>
scroll: Accessor<{ overflow: boolean; jump: boolean }>
onResumeScroll: () => void
onResumeScroll: (behavior?: ScrollBehavior) => void
setScrollRef: (element: HTMLDivElement | undefined) => void
setContentRef: (element: HTMLDivElement) => void
onScheduleScrollState: (element: HTMLDivElement) => void
@@ -77,7 +77,7 @@ type Input = {
disclosure: Readonly<Record<string, boolean | undefined>>,
) => boolean
setRevealMessage?: (fn: (id: string, partID?: string) => void) => void
setScrollToEnd?: (fn: () => void) => void
setScrollToEnd?: (fn: (behavior?: ScrollBehavior) => void) => void
/** A tool call the route asks this timeline to open on; `done` clears it once revealed. */
reveal?: { target: () => string | undefined; done: () => void }
}
@@ -528,11 +528,17 @@ export function createTimelineVirtualizer(input: Input) {
prepareNavigation()
virtualizer.scrollToIndex(index, { align: "center" })
})
input.setScrollToEnd?.(() => {
if (!active() || !listRoot()?.isConnected) return
input.setScrollToEnd?.((behavior) => {
const root = listRoot()
if (!active() || !root?.isConnected) return
prepareNavigation()
input.onPin()
virtualizer.scrollToEnd()
// Glide only the final screen. Crossing the whole history smoothly would stream every row through the virtualizer.
if (behavior === "smooth")
virtualizer.scrollToOffset(Math.max(root.scrollTop, root.scrollHeight - root.clientHeight * 2))
virtualizer.scrollToEnd({ behavior })
})
})
@@ -847,23 +853,27 @@ export function createTimelineVirtualizer(input: Input) {
data-local-session={!props.workspaceSession() ? "" : undefined}
>
<div
class="absolute left-1/2 -translate-x-1/2 z-[60] pointer-events-none transition-all duration-200 ease-out"
class="absolute left-1/2 -translate-x-1/2 z-[60] pointer-events-none transition-[opacity,translate]"
classList={{
"bottom-8": true,
"opacity-100 translate-y-0 scale-100": input.scroll().overflow && input.scroll().jump,
"opacity-0 translate-y-2 pointer-events-none": !input.scroll().overflow || !input.scroll().jump,
"scale-[0.8]": !input.scroll().overflow || !input.scroll().jump,
"opacity-100 translate-y-0 duration-150 ease-[cubic-bezier(.2,.8,.2,1)]":
input.scroll().overflow && input.scroll().jump,
"opacity-0 translate-y-1 motion-reduce:translate-y-0 duration-[110ms] ease-[cubic-bezier(.4,0,1,1)]":
!input.scroll().overflow || !input.scroll().jump,
}}
inert={!input.scroll().overflow || !input.scroll().jump}
>
<button
type="button"
aria-label={language.t("session.messages.jumpToLatest")}
class="pointer-events-auto flex items-center justify-center w-8 h-7 px-2 py-1.5 rounded-lg border-none cursor-pointer text-v2-text-text-base backdrop-blur-[2px]"
class="pointer-events-auto flex items-center justify-center w-8 h-7 px-2 py-1.5 rounded-lg border-none cursor-pointer text-v2-text-text-base backdrop-blur-[2px] outline-none hover:bg-[linear-gradient(var(--v2-overlay-simple-overlay-hover),var(--v2-overlay-simple-overlay-hover))] active:bg-[linear-gradient(var(--v2-overlay-simple-overlay-pressed),var(--v2-overlay-simple-overlay-pressed))] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-v2-border-border-focus"
style={{
background: "color-mix(in srgb, var(--v2-background-bg-base) 92%, transparent)",
"background-color": "color-mix(in srgb, var(--v2-background-bg-base) 92%, transparent)",
"box-shadow": "var(--v2-elevation-raised), 0px 2px 8px var(--v2-background-bg-base)",
}}
onClick={input.onResumeScroll}
onClick={() =>
input.onResumeScroll(matchMedia("(prefers-reduced-motion: reduce)").matches ? "auto" : "smooth")
}
>
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true">
<path