Compare commits

...
Author SHA1 Message Date
paseo-bot[bot] c33463f414 fix(app): preserve an upward scroll before its event arrives
Check for actual upward movement before pinning the viewport to streamed output. This covers mixed-axis gestures that move the chat before the scroll handler runs.
2026-11-21 00:32:56 +00:00
paseo-bot[bot] ff07ad0cda fix(app): confirm upward scrolling for mixed-axis wheel gestures
A diagonal gesture can move a nested scroller sideways while the chat stays in place. Wait for vertical viewport movement before stopping follow-output for that gesture.
2026-11-21 00:26:12 +00:00
paseo-bot[bot] 8226a824ee fix(app): keep chat following during horizontal wheel input
Chromium routes Shift+wheel horizontally even when the wheel event reports a negative vertical delta.
2026-11-21 00:18:48 +00:00
paseo-bot[bot] fc9e1b0a3c fix(app): keep chat in place after scrolling up during a stream
Pause follow-output when the viewport receives an eligible upward wheel gesture. Browser scroll delivery can lag behind an output update that would otherwise return the reader to the bottom.
2026-11-21 00:10:01 +00:00
2 changed files with 123 additions and 16 deletions
@@ -1,6 +1,7 @@
import React, { act } from "react";
import { createRoot, type Root } from "react-dom/client";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { userEvent } from "vitest/browser";
import { DEFAULT_CONTENT_MAX_WIDTH } from "@/styles/theme";
import type { StreamItem } from "@/types/stream";
import type { DisclosureTriggerEdge, StreamRenderInput, StreamViewportHandle } from "./strategy";
@@ -115,10 +116,31 @@ function mountTimeline(
scrollContainer.scrollTop = top;
},
// A wheel listener runs before the browser applies the scroll the wheel causes.
wheelUpTo: (top: number) => {
scrollContainer.dispatchEvent(new WheelEvent("wheel", { bubbles: true, deltaY: -1000 }));
wheelUpTo: (top: number, deltaX = 0) => {
scrollContainer.dispatchEvent(
new WheelEvent("wheel", { bubbles: true, deltaX, deltaY: -1000 }),
);
scrollContainer.scrollTop = top;
},
shiftWheelUp: () =>
act(async () => {
await userEvent.keyboard("{Shift>}");
try {
await userEvent.wheel(scrollContainer, { delta: { y: -120 } });
} finally {
await userEvent.keyboard("{/Shift}");
}
}),
wheelSidewaysOverRow: async (rowId: string) => {
const scroller = document.createElement("div");
scroller.style.cssText = "width: 100px; height: 18px; overflow-x: auto";
const wideContent = document.createElement("div");
wideContent.style.cssText = "width: 800px; height: 16px";
scroller.append(wideContent);
act(() => rowElement(rowId).append(scroller));
await act(async () => userEvent.wheel(scroller, { delta: { x: 120, y: -1 } }));
await expect.poll(() => scroller.scrollLeft).toBeGreaterThan(0);
},
distanceFromEnd: () =>
scrollContainer.scrollHeight - scrollContainer.clientHeight - scrollContainer.scrollTop,
scrollTop: () => scrollContainer.scrollTop,
@@ -282,6 +304,54 @@ describe("web disclosure hold", () => {
});
});
describe("web output following", () => {
it.each([0, 1])(
"keeps the reading position when stream output grows before the wheel scroll event (horizontal delta %s)",
async (deltaX) => {
const history = Array.from({ length: 20 }, (_, index) => row(index));
const timeline = mountTimeline(history);
await timeline.settle();
expect(timeline.distanceFromEnd()).toBeLessThanOrEqual(1);
const readingOffset = timeline.scrollTop() - 400;
timeline.wheelUpTo(readingOffset, deltaX);
// Stream output can commit before the browser delivers the scroll event.
timeline.render({ historyMounted: [...history, row(20)] });
await timeline.settle();
expect(timeline.scrollTop()).toBe(readingOffset);
},
);
it("keeps following output after horizontal Shift+wheel", async () => {
const history = Array.from({ length: 20 }, (_, index) => row(index));
const timeline = mountTimeline(history);
await timeline.settle();
expect(timeline.distanceFromEnd()).toBeLessThanOrEqual(1);
await timeline.shiftWheelUp();
await timeline.settle();
expect(timeline.distanceFromEnd()).toBeLessThanOrEqual(1);
timeline.render({ historyMounted: [...history, row(20)] });
await timeline.settle();
expect(timeline.distanceFromEnd()).toBeLessThanOrEqual(1);
});
it("keeps following when diagonal wheel input scrolls a nested row sideways", async () => {
const history = Array.from({ length: 20 }, (_, index) => row(index));
const timeline = mountTimeline(history);
await timeline.settle();
expect(timeline.distanceFromEnd()).toBeLessThanOrEqual(1);
await timeline.wheelSidewaysOverRow("message-19");
expect(timeline.distanceFromEnd()).toBeLessThanOrEqual(1);
timeline.render({ historyMounted: [...history, row(20)] });
await timeline.settle();
expect(timeline.distanceFromEnd()).toBeLessThanOrEqual(1);
});
});
describe("web history start", () => {
it("loads older history when an upward wheel lands at the start after the reader stopped following", async () => {
let olderHistoryLoads = 0;
+51 -14
View File
@@ -641,6 +641,15 @@ function WebStreamViewport(props: StreamRenderInput & { isMobileBreakpoint: bool
lastTouchClientYRef.current = null;
}, [cancelPendingStickToBottom, clearMouseScrollGesture, clearUpwardInputEvidence, isActive]);
const stopFollowingOutputFromUserIntent = useStableEvent(() => {
finishInitialFill();
cancelPendingStickToBottom();
if (followOutputRef.current) {
setFollowOutput(false);
}
rearmHistoryStartFromUserIntent();
});
const scrollMessagesToBottom = useCallback(
(behavior: ScrollBehaviorLike = "auto") => {
const scrollContainer = scrollContainerRef.current;
@@ -654,12 +663,26 @@ function WebStreamViewport(props: StreamRenderInput & { isMobileBreakpoint: bool
if (isScrollContainerOverscrolledPastBottom(scrollContainer)) {
return;
}
// A stream commit can run after the browser moves the viewport but
// before the scroll handler sees the new position.
if (
hasUpwardInputEvidence() &&
scrollContainer.scrollTop < lastKnownScrollTopRef.current - USER_SCROLL_DELTA_EPSILON
) {
stopFollowingOutputFromUserIntent();
return;
}
scrollElementToBottom(scrollContainer, behavior);
lastKnownScrollTopRef.current = scrollContainer.scrollTop;
syncNearBottom(scrollContainer, onNearBottomChange);
evaluateHistoryStart();
},
[evaluateHistoryStart, onNearBottomChange],
[
evaluateHistoryStart,
hasUpwardInputEvidence,
onNearBottomChange,
stopFollowingOutputFromUserIntent,
],
);
const scheduleStickToBottom = useCallback(() => {
@@ -792,15 +815,6 @@ function WebStreamViewport(props: StreamRenderInput & { isMobileBreakpoint: bool
reconcileReadingPosition,
]);
const stopFollowingOutputFromUserIntent = useStableEvent(() => {
finishInitialFill();
cancelPendingStickToBottom();
if (followOutputRef.current) {
setFollowOutput(false);
}
rearmHistoryStartFromUserIntent();
});
useEffect(() => {
if (revealInitialHistory) finishInitialFill();
}, [finishInitialFill, revealInitialHistory]);
@@ -1052,12 +1066,29 @@ function WebStreamViewport(props: StreamRenderInput & { isMobileBreakpoint: bool
};
const handleWheel = (event: WheelEvent) => {
if (
!event.ctrlKey &&
event.deltaY < 0 &&
!canNestedScrollerConsumeUpwardInput(event.target, scrollContainer)
event.defaultPrevented ||
event.ctrlKey ||
event.shiftKey || // Browsers use Shift+wheel to scroll horizontally.
event.deltaY >= 0 ||
!scrollEnabled ||
canNestedScrollerConsumeUpwardInput(event.target, scrollContainer)
) {
markUpwardViewportInput();
return;
}
// A vertical wheel gesture can arrive before the browser moves the viewport.
// Mixed-axis gestures may move nested content sideways, so wait for an upward scroll.
if (
event.deltaX === 0 &&
followOutputRef.current &&
Math.max(scrollContainer.scrollTop, lastKnownScrollTopRef.current) >
USER_SCROLL_DELTA_EPSILON
) {
stopFollowingOutputFromUserIntent();
return;
}
markUpwardViewportInput();
};
const handleKeyDown = (event: KeyboardEvent) => {
if (!isUpwardViewportScrollKey(event)) {
@@ -1184,12 +1215,16 @@ function WebStreamViewport(props: StreamRenderInput & { isMobileBreakpoint: bool
isActive,
markUpwardInputEvidence,
rearmHistoryStartFromUserIntent,
scrollEnabled,
stopFollowingOutputFromUserIntent,
]);
useEffect(() => {
const handle: StreamViewportHandle = {
focus: () => scrollContainerRef.current?.focus({ preventScroll: true }),
scrollToBottom: () => {
clearMouseScrollGesture();
clearUpwardInputEvidence();
setFollowOutput(true);
cancelPendingStickToBottom();
forceStickToBottom();
@@ -1220,6 +1255,8 @@ function WebStreamViewport(props: StreamRenderInput & { isMobileBreakpoint: bool
};
}, [
cancelPendingStickToBottom,
clearMouseScrollGesture,
clearUpwardInputEvidence,
forceStickToBottom,
measureRows,
readingAnchor,