@devries-cameron20 / t3code-1 / commits / 7e101444a1
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): scrolling over an inline HTML render no longer snaps back to the bottom (#17065)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Joseph Vidal committed Oct 20, 2026 at 01:08 UTC 7e101444a1feb0e5e980cf73c98c9710f1a3e41e
3 files changed +89 -26
apps/web/src/components/ChatView.tsx
+45 -25
@@ -397,7 +397,7 @@ import {
397 import { environmentShell, useEnvironmentShellHasSnapshot } from "../state/shell";
398 import { ChatComposer, type ChatComposerHandle } from "./chat/ChatComposer";
399 import { createPageScrollController, type PageScrollKey } from "./chat/pageScrollController";
400 -import { isTimelineScrollTarget } from "./chat/timelineScrollTarget";
400 +import { createUpwardScrollDetector, isTimelineScrollTarget } from "./chat/timelineScrollTarget";
401 import { DraftHeroHeadline } from "./chat/DraftHeroHeadline";
402 import { ExpandedImageDialogHost, openExpandedImagePreview } from "./chat/ExpandedImageDialog";
403 import {
@@ -4295,6 +4295,33 @@ export default function ChatView(props: ChatViewProps) {
4295 break;
4296 }
4297 };
4298 + // Input inside an embedded frame reaches none of the listeners above,
4299 + // but its scroll still chains out to the timeline (#17056).
4300 + const scrolledUp = createUpwardScrollDetector({
4301 + top: scrollNode.scrollTop,
4302 + height: scrollNode.scrollHeight,
4303 + });
4304 + const handleScroll = () => {
4305 + if (
4306 + scrolledUp({
4307 + top: scrollNode.scrollTop,
4308 + height: scrollNode.scrollHeight,
4309 + programmatic:
4310 + positionedTimelineAnchorRef.current !== null &&
4311 + positionedTimelineAnchorRef.current !== settledTimelineAnchorRef.current,
4312 + }) &&
4313 + timelineScrollModeRef.current !== "free-scrolling" &&
4314 + // LegendList updates its scroll state on the next animation frame.
4315 + resolveTimelineIsAtEnd({
4316 + contentLength: scrollNode.scrollHeight,
4317 + scroll: scrollNode.scrollTop,
4318 + scrollLength: scrollNode.clientHeight,
4319 + }) === false
4320 + ) {
4321 + handleManualNavigation();
4322 + }
4323 + };
4324 + scrollNode.addEventListener("scroll", handleScroll, { passive: true });
4325 scrollNode.addEventListener("wheel", handleWheel, {
4326 passive: true,
4327 });
@@ -4306,6 +4333,7 @@ export default function ChatView(props: ChatViewProps) {
4333 });
4334 document.addEventListener("keydown", handleKeyDown);
4335 removeListeners = () => {
4336 + scrollNode.removeEventListener("scroll", handleScroll);
4337 scrollNode.removeEventListener("wheel", handleWheel);
4338 scrollNode.removeEventListener("touchmove", handleTouchMove);
4339 scrollNode.removeEventListener("pointerdown", handlePointerDown);
@@ -4351,30 +4379,22 @@ export default function ChatView(props: ChatViewProps) {
4379 }
4380 return;
4381 }
4354 - const scrollNode = list.getScrollableNode();
4355 - let finished = false;
4356 - const finishAnimatedPositioning = () => {
4357 - if (finished) {
4358 - return;
4359 - }
4360 - finished = true;
4361 - window.clearTimeout(fallbackTimer);
4362 - scrollNode.removeEventListener("scrollend", finishAnimatedPositioning);
4363 - if (positionedTimelineAnchorRef.current !== messageId) {
4364 - return;
4365 - }
4366 - const scrollOffset = list.getState().scroll;
4367 - void list.scrollToOffset({ offset: scrollOffset, animated: false });
4368 - settledTimelineAnchorRef.current = messageId;
4369 - };
4370 - const fallbackTimer = window.setTimeout(finishAnimatedPositioning, 750);
4371 - scrollNode.addEventListener("scrollend", finishAnimatedPositioning, { once: true });
4372 - void list.scrollToIndex({
4373 - index: anchorIndex,
4374 - animated: !window.matchMedia("(prefers-reduced-motion: reduce)").matches,
4375 - viewPosition: 0,
4376 - viewOffset: CHAT_LIST_ANCHOR_OFFSET,
4377 - });
4382 + // LegendList waits for queued layout and the animation before resolving.
4383 + void list
4384 + .scrollToIndex({
4385 + index: anchorIndex,
4386 + animated: !window.matchMedia("(prefers-reduced-motion: reduce)").matches,
4387 + viewPosition: 0,
4388 + viewOffset: CHAT_LIST_ANCHOR_OFFSET,
4389 + })
4390 + .then(() => {
4391 + if (
4392 + legendListRef.current === list &&
4393 + positionedTimelineAnchorRef.current === messageId
4394 + ) {
4395 + settledTimelineAnchorRef.current = messageId;
4396 + }
4397 + });
4398 });
4399 };
4400 requestAnimationFrame(() => positionAnchor(12));
apps/web/src/components/chat/timelineScrollTarget.test.ts
+26 -1
@@ -4,7 +4,7 @@ import {
4 createComposerScrollGestureState,
5 recordComposerScrollGestureEvent,
6 } from "./composerScrollGesture";
7 -import { isTimelineScrollTarget } from "./timelineScrollTarget";
7 +import { createUpwardScrollDetector, isTimelineScrollTarget } from "./timelineScrollTarget";
8
9 class ScrollElement extends EventTarget {
10 scrollTop = 0;
@@ -140,3 +140,28 @@ describe("timeline scroll targets", () => {
140 expect(record(content, 60, 14)).toBe(true);
141 });
142 });
143 +
144 +describe("timeline scroll follow opt-out", () => {
145 + it("detects iframe-only upward scrolling after following streaming content", () => {
146 + const scrolledUp = createUpwardScrollDetector({ top: 1000, height: 1500 });
147 + expect(scrolledUp({ top: 1000, height: 1800 })).toBe(false);
148 + expect(scrolledUp({ top: 1300, height: 1800 })).toBe(false);
149 + expect(scrolledUp({ top: 1200, height: 1700 })).toBe(false);
150 +
151 + // Sandboxed frames deliver no wheel or touch event to the parent timeline.
152 + expect(scrolledUp({ top: 1199.5, height: 1700 })).toBe(false);
153 + expect(scrolledUp({ top: 1199, height: 1700 })).toBe(false);
154 + expect(scrolledUp({ top: 1198.5, height: 1700 })).toBe(true);
155 + });
156 +
157 + it("preserves upward new-turn positioning, then detects the reader leaving that anchor", () => {
158 + const scrolledUp = createUpwardScrollDetector({ top: 1400, height: 2400 });
159 + // The caller must distinguish its animated positioning from iframe scroll chaining.
160 + const positioning = { top: 1200, height: 2400, programmatic: true };
161 + expect(scrolledUp(positioning)).toBe(false);
162 + expect(scrolledUp({ ...positioning, top: 1100 })).toBe(false);
163 +
164 + expect(scrolledUp({ top: 1100, height: 2400 })).toBe(false);
165 + expect(scrolledUp({ top: 950, height: 2400 })).toBe(true);
166 + });
167 +});
apps/web/src/components/chat/timelineScrollTarget.ts
+18
@@ -27,3 +27,21 @@ export function isTimelineScrollTarget(
27 }
28 return true;
29 }
30 +
31 +// Sandboxed iframe gestures are invisible to the parent; only their chained scroll arrives.
32 +export function createUpwardScrollDetector(initial: { top: number; height: number }) {
33 + let baseline = initial;
34 + return (next: { top: number; height: number; programmatic?: boolean }) => {
35 + if (next.programmatic || next.height < baseline.height || next.top > baseline.top) {
36 + baseline = next;
37 + return false;
38 + }
39 + if (next.top < baseline.top - 1) {
40 + baseline = next;
41 + return true;
42 + }
43 + // A slow scroll can move under a pixel per event; let those moves add up.
44 + baseline = { top: baseline.top, height: next.height };
45 + return false;
46 + };
47 +}