-
+
) : (
@@ -1319,7 +1355,7 @@ export const ThreadViewport = forwardRef
) : null}
- {showScrollToBottomButton && (!atBottom || historyWindow) && (
+ {showScrollToBottomButton && (historyWindow || (contentBelowViewport && !navigatingToBottom)) && (
boolean;
+ onSettled?: () => void;
}
function defaultScheduler(): ThreadCameraScheduler {
@@ -38,6 +39,7 @@ export class ThreadCameraController {
private readonly getViewport: () => ThreadCameraViewport | null;
private readonly scheduler: ThreadCameraScheduler;
private readonly prefersReducedMotion: () => boolean;
+ private readonly onSettled?: () => void;
private frameId: number | null = null;
private phase: "idle" | "following" = "idle";
private target = 0;
@@ -50,6 +52,7 @@ export class ThreadCameraController {
) {
this.getViewport = getViewport;
this.scheduler = options.scheduler ?? defaultScheduler();
+ this.onSettled = options.onSettled;
this.prefersReducedMotion = options.prefersReducedMotion ?? defaultPrefersReducedMotion;
}
@@ -132,6 +135,7 @@ export class ThreadCameraController {
if (remainingMs === 0) {
this.write(viewport, this.target);
this.cancel();
+ this.onSettled?.();
return;
}
diff --git a/webui/src/components/thread/thread-motion.ts b/webui/src/components/thread/thread-motion.ts
index 3a99fc119..fb8dd3f04 100644
--- a/webui/src/components/thread/thread-motion.ts
+++ b/webui/src/components/thread/thread-motion.ts
@@ -44,6 +44,7 @@ const THREAD_MOTION_TRANSITIONS: Readonly<
"resume-follow": "current-automatic-mode",
},
"follow-latest": {
+ "navigate-latest": "navigating-latest",
"navigate-history": "navigating-history",
"user-scroll": "browsing-history",
},
@@ -134,6 +135,7 @@ interface ThreadMotionCoordinatorOptions {
measure: (promptId: string | null) => ThreadMotionGeometry | null;
onGeometry?: (geometry: ThreadMotionGeometry) => void;
onAutoFollow?: () => void;
+ onLatestNavigationSettled?: () => void;
scheduler?: ThreadMotionScheduler;
}
@@ -159,6 +161,7 @@ export class ThreadMotionCoordinator {
private readonly measure: ThreadMotionCoordinatorOptions["measure"];
private readonly onGeometry?: ThreadMotionCoordinatorOptions["onGeometry"];
private readonly onAutoFollow?: ThreadMotionCoordinatorOptions["onAutoFollow"];
+ private readonly onLatestNavigationSettled?: () => void;
private readonly scheduler: ThreadMotionScheduler;
private turn: ThreadMotionTurn = {
id: null,
@@ -180,6 +183,7 @@ export class ThreadMotionCoordinator {
this.measure = options.measure;
this.onGeometry = options.onGeometry;
this.onAutoFollow = options.onAutoFollow;
+ this.onLatestNavigationSettled = options.onLatestNavigationSettled;
this.scheduler = options.scheduler ?? defaultScheduler();
}
@@ -330,6 +334,13 @@ export class ThreadMotionCoordinator {
return result;
}
+ cameraSettled(): void {
+ if (this.mode === "navigating-latest") {
+ this.settleLatestNavigation();
+ this.onLatestNavigationSettled?.();
+ }
+ }
+
isAutoFollowPaused(): boolean {
return this.isHistoryMode();
}
diff --git a/webui/src/tests/thread-motion.test.ts b/webui/src/tests/thread-motion.test.ts
index d2cd7aa78..ff5c886ea 100644
--- a/webui/src/tests/thread-motion.test.ts
+++ b/webui/src/tests/thread-motion.test.ts
@@ -587,6 +587,34 @@ describe("ThreadMotionCoordinator", () => {
expect(coordinator.snapshot().mode).toBe("browsing-history");
});
+ it("settles camera navigation without relying on a scroll event", () => {
+ const { coordinator } = motionHarness();
+ coordinator.takeUserControl();
+ coordinator.navigateLatestTo(1_400);
+ coordinator.cameraSettled();
+ expect(coordinator.snapshot().mode).toBe("follow-latest");
+
+ coordinator.navigateHistoryTo(200);
+ coordinator.cameraSettled();
+ expect(coordinator.snapshot().mode).toBe("navigating-history");
+ });
+
+ it("keeps explicit latest navigation in control when already following the tail", () => {
+ const { camera, coordinator, advanceFrame, setCameraFollowing } = motionHarness();
+ coordinator.resumeAutoFollow();
+ advanceFrame();
+
+ expect(coordinator.snapshot().mode).toBe("follow-latest");
+ expect(coordinator.navigateLatestTo(1_400)).toBe("started");
+ expect(coordinator.snapshot().mode).toBe("navigating-latest");
+ expect(coordinator.observeScroll(true)).toBe("navigation");
+ expect(camera.isFollowing()).toBe(true);
+
+ setCameraFollowing(false);
+ coordinator.cameraSettled();
+ expect(coordinator.snapshot().mode).toBe("follow-latest");
+ });
+
it("retargets smooth latest navigation before resuming automatic follow", () => {
const {
camera,
diff --git a/webui/src/tests/thread-viewport.test.tsx b/webui/src/tests/thread-viewport.test.tsx
index 55a5b98db..4716b74d7 100644
--- a/webui/src/tests/thread-viewport.test.tsx
+++ b/webui/src/tests/thread-viewport.test.tsx
@@ -201,6 +201,14 @@ function getScroller(container: HTMLElement): HTMLElement {
return scroller;
}
+function mockMessageEnd(scroller: HTMLElement) {
+ const rows = scroller.querySelectorAll(".thread-message-row");
+ const row = rows[rows.length - 1];
+ scroller.getBoundingClientRect = () => ({ bottom: scroller.clientHeight } as DOMRect);
+ row.getBoundingClientRect = () => ({ height: 100, bottom: scroller.scrollHeight - scroller.scrollTop } as DOMRect);
+ act(() => window.dispatchEvent(new Event("resize")));
+}
+
async function renderPromptRailViewport({
scrollTo,
messages: promptMessages = makePromptExchangeMessages(5),
@@ -922,6 +930,7 @@ describe("ThreadViewport", () => {
await flushAnimationFrame();
followTo.mockClear();
+ mockMessageEnd(scroller);
act(() => {
fireEvent.wheel(scroller, { deltaY: -24 });
scroller.scrollTop = 1_380;
@@ -970,6 +979,43 @@ describe("ThreadViewport", () => {
.not.toBeInTheDocument();
});
+ it("tracks the message content edge independently of trailing space and motion ownership", () => {
+ const resizeObserver = stubResizeObserver();
+ try {
+ const { container } = render(composer
} />);
+ const scroller = getScroller(container);
+ const content = scroller.firstElementChild as HTMLElement;
+ const row = scroller.querySelector(".thread-message-row:last-child")!;
+ const gap = scroller.querySelector(".thread-message-end-gap")!;
+ let contentBottom = 565;
+ scroller.getBoundingClientRect = () => ({ bottom: 600 } as DOMRect);
+ gap.getBoundingClientRect = () => ({ height: 36 } as DOMRect);
+ row.getBoundingClientRect = () => ({ bottom: contentBottom, height: 100 } as DOMRect);
+ act(() => window.dispatchEvent(new Event("resize")));
+ Object.defineProperties(scroller, {
+ scrollHeight: { configurable: true, value: 1000 },
+ clientHeight: { configurable: true, value: 600 },
+ scrollTop: { configurable: true, writable: true, value: 300 },
+ });
+ act(() => { scroller.dispatchEvent(new Event("scroll")); });
+ expect(screen.getByRole("button", { name: "Scroll to bottom" })).toBeInTheDocument();
+ contentBottom = 564;
+ act(() => { scroller.dispatchEvent(new Event("scroll")); });
+ expect(screen.queryByRole("button", { name: "Scroll to bottom" })).not.toBeInTheDocument();
+ contentBottom = 570;
+ const observer = resizeObserver.observers.find((item) => item.elements.includes(content))!;
+ act(() => { observer.callback([], observer); });
+ expect(screen.getByRole("button", { name: "Scroll to bottom" })).toBeInTheDocument();
+ vi.spyOn(ThreadMotionCoordinator.prototype, "navigateLatestTo").mockReturnValue("started");
+ fireEvent.click(screen.getByRole("button", { name: "Scroll to bottom" }));
+ expect(screen.queryByRole("button", { name: "Scroll to bottom" })).not.toBeInTheDocument();
+ fireEvent.wheel(scroller, { deltaY: -20 });
+ expect(screen.getByRole("button", { name: "Scroll to bottom" })).toBeInTheDocument();
+ } finally {
+ resizeObserver.restore();
+ }
+ });
+
it("keeps the scroll-to-bottom button above a growing composer", async () => {
const resizeObserver = stubResizeObserver();
@@ -988,6 +1034,7 @@ describe("ThreadViewport", () => {
scrollTop: { configurable: true, value: 0 },
});
+ mockMessageEnd(scroller);
act(() => {
dispatchUserScroll(scroller);
});
@@ -1046,6 +1093,7 @@ describe("ThreadViewport", () => {
scrollTop: { configurable: true, writable: true, value: 0 },
});
+ mockMessageEnd(scroller);
act(() => {
dispatchUserScroll(scroller);
});
@@ -2379,6 +2427,7 @@ describe("ThreadViewport", () => {
clientHeight: { configurable: true, value: 600 },
scrollTop: { configurable: true, writable: true, value: 300 },
});
+ mockMessageEnd(scroller);
act(() => {
dispatchUserScroll(scroller);
});