The best way to control Claude Code, Codex and more from any computer or phone
fix(web): reveal expanded work rows hidden behind the composer (#21968)
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>
LN Bodicherla committed
Nov 11, 2026 at 04:05 UTC
6700cf6f894b34cc76bf93ea3bdd33f0573c6855
9 files changed
+422
-19
apps/web/src/components/chat/CommandOutputPanel.tsx
+3
-1
@@ -7,7 +7,7 @@ import { useTheme } from "../../hooks/useTheme";
7
import { useServerConfigs } from "../../state/entities";
8
import { orchestrationEnvironment } from "../../state/orchestration";
9
import { useEnvironmentQuery } from "../../state/query";
10
-import type { TurnItemSource } from "./timelineRowContext";
10
+import { useInitialOutputReady, type TurnItemSource } from "./timelineRowContext";
11
12
const FOLLOW_SLACK_PX = 8;
13
@@ -24,6 +24,7 @@ export function useCommandOutputStreaming(environmentId: EnvironmentId): boolean
24
* It subscribes only while mounted, so collapsed rows and other threads receive nothing.
25
*/
26
export function CommandOutputPanel(props: {
27
+ readonly onInitialOutputReady?: (() => void) | undefined;
28
readonly environmentId: EnvironmentId;
29
readonly threadId: ThreadId;
30
readonly itemId: TurnItemId;
@@ -35,6 +36,7 @@ export function CommandOutputPanel(props: {
36
? props.source(input)
37
: orchestrationEnvironment.v2.commandOutput({ environmentId: props.environmentId, input }),
38
);
39
+ useInitialOutputReady(data === null && !error, props.onInitialOutputReady);
40
const scrollRef = useRef<HTMLDivElement>(null);
41
const followRef = useRef(true);
42
const text = data?.output.text ?? "";
apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
+218
-2
@@ -28,7 +28,7 @@ import {
28
type ReactElement,
29
} from "react";
30
import * as DateTime from "effect/DateTime";
31
-import { Atom } from "effect/reactivity";
31
+import { Atom, AsyncResult } from "effect/reactivity";
32
import { describe, expect, it, onTestFinished, vi } from "vite-plus/test";
33
34
import "~/index.css";
@@ -37,6 +37,7 @@ import { environmentThreadDetails } from "../../state/threads";
37
import { act, fakeTimers, render, stubGlobal } from "../../../test/render";
38
import { ChangedFilesCard } from "./ChangedFilesTree";
39
import { MessagesTimeline } from "./MessagesTimeline";
40
+import { resolveTimelineIsAtEnd } from "./MessagesTimeline.logic";
41
import { makeStreamingTimelineFixture } from "../../test-fixtures";
42
import {
43
type PendingApproval,
@@ -56,7 +57,7 @@ import {
57
import { collectComposerContextReferences } from "@t3tools/shared/composerContextReferences";
58
59
const environmentQuery = vi.hoisted(() => ({
59
- error: "Pull request not found",
60
+ error: "Pull request not found" as string | null,
61
data: null as unknown,
62
}));
63
vi.mock(import("~/state/query"), async (original) => ({
@@ -212,6 +213,7 @@ async function click(element: HTMLElement) {
213
}
214
215
function setup({ scheduledTasks = [] as ReadonlyArray<{ id: string; title: string }> } = {}) {
216
+ environmentQuery.error = "Pull request not found";
217
environmentQuery.data = { tasks: scheduledTasks };
218
}
219
@@ -773,6 +775,220 @@ describe("MessagesTimeline messages", () => {
775
await click(screen.button("Safe details"));
776
expect((globalThis as { __t3Xss?: number }).__t3Xss).toBeUndefined();
777
});
778
+
779
+ const revealModes = ["inline", "at-end", "delayed", "grouped-delayed", "grouped-end"];
780
+ it.each(revealModes)("reveals %s output", async (mode) => {
781
+ const inline = mode === "inline" || mode === "at-end";
782
+ setup();
783
+ environmentQuery.data =
784
+ mode === "grouped-end"
785
+ ? {
786
+ output: { text: `${"output line\n".repeat(10)}TOOL_INPUT_END`, truncated: false },
787
+ running: false,
788
+ }
789
+ : null;
790
+ environmentQuery.error = null;
791
+ const props = baseProps();
792
+ const composerOverlayHeight = mode === "grouped-end" ? 140 : 200;
793
+ const tallEntries = Array.from({ length: 12 }, (_, index) =>
794
+ message(
795
+ `Message ${index}\n\n${"Long paragraph. ".repeat(80)}`,
796
+ { role: "assistant" },
797
+ `tall-${index}`,
798
+ ),
799
+ );
800
+ const projectedItem = makeStreamingTimelineFixture().visibleTurnItems[1]!;
801
+ const source = {
802
+ detail: () => Atom.make(AsyncResult.initial()),
803
+ commandOutput: () => Atom.make(AsyncResult.initial()),
804
+ };
805
+ let outerGrowth = false;
806
+ let routeThreadKey = props.routeThreadKey;
807
+ const timeline = () => (
808
+ <MessagesTimeline
809
+ {...props}
810
+ routeThreadKey={routeThreadKey}
811
+ liveFollowEnabled={false}
812
+ {...(inline
813
+ ? {}
814
+ : {
815
+ turnItemSource: {
816
+ detail: () => source.detail(),
817
+ commandOutput: () => source.commandOutput(),
818
+ },
819
+ })}
820
+ contentInsetEndAdjustment={composerOverlayHeight}
821
+ timelineEntries={[
822
+ ...tallEntries.slice(0, 6),
823
+ {
824
+ id: "tool-near-composer",
825
+ kind: "work",
826
+ createdAt: CREATED_AT,
827
+ entry: {
828
+ id: "tool-near-composer",
829
+ createdAt: CREATED_AT,
830
+ label: "Example tool",
831
+ toolTitle: "Example tool",
832
+ tone: "tool",
833
+ itemType: "dynamic_tool",
834
+ toolLifecycleStatus: "completed",
835
+ toolData: { input: { query: `${"x".repeat(1200)} TOOL_INPUT_END` } },
836
+ ...(inline
837
+ ? {}
838
+ : {
839
+ itemType: "command_execution",
840
+ projectedItem,
841
+ structuredPayload: projectedItem.item,
842
+ }),
843
+ },
844
+ },
845
+ ...(mode.startsWith("grouped-")
846
+ ? [
847
+ {
848
+ id: "another-tool",
849
+ kind: "work" as const,
850
+ createdAt: CREATED_AT,
851
+ entry: {
852
+ id: "another-tool",
853
+ createdAt: CREATED_AT,
854
+ label: "Other tool",
855
+ tone: "tool" as const,
856
+ itemType: "dynamic_tool" as const,
857
+ toolLifecycleStatus: "completed" as const,
858
+ toolData: { input: { query: "other" } },
859
+ },
860
+ },
861
+ ]
862
+ : []),
863
+ ...(mode === "grouped-end"
864
+ ? [message("Completed.", { role: "assistant" }, "final-message")]
865
+ : mode === "at-end"
866
+ ? [message("Done.", { role: "assistant" }, "final-message")]
867
+ : tallEntries.slice(6)),
868
+ ...(outerGrowth
869
+ ? [message("Later output\n\n".repeat(20), { role: "assistant" }, "outer-growth")]
870
+ : []),
871
+ ]}
872
+ />
873
+ );
874
+ await using screen = await renderElement(
875
+ mode === "grouped-delayed" ? (
876
+ <MessagesTimeline {...props} timelineEntries={[message("Previous thread")]} />
877
+ ) : (
878
+ timeline()
879
+ ),
880
+ );
881
+ if (mode === "grouped-end") screen.container.style.height = "648px";
882
+ await vi.waitFor(() => expect(props.listRef.current?.getScrollableNode()).toBeTruthy());
883
+ const viewport = props.listRef.current!.getScrollableNode()!;
884
+ if (mode === "grouped-delayed") {
885
+ routeThreadKey = `${routeThreadKey}-switched`;
886
+ await screen.rerender(timeline());
887
+ await vi.waitFor(() => expect(viewport.scrollHeight).toBeGreaterThan(3000));
888
+ await act(() => viewport.dispatchEvent(new WheelEvent("wheel", { deltaY: -1 })));
889
+ }
890
+ if (mode.startsWith("grouped-")) {
891
+ await act(() => {
892
+ void props.listRef.current!.scrollToIndex({ index: 6, animated: false });
893
+ });
894
+ await vi.waitFor(() =>
895
+ expect(
896
+ screen.container.querySelector('[data-timeline-row-kind="work-toggle"] button'),
897
+ ).not.toBeNull(),
898
+ );
899
+ const group = () =>
900
+ screen.container.querySelector<HTMLElement>(
901
+ '[data-timeline-row-kind="work-toggle"] button',
902
+ )!;
903
+ await click(group());
904
+ await vi.waitFor(() =>
905
+ expect(
906
+ screen.container.querySelector('[data-work-entry-id="tool-near-composer"]'),
907
+ ).not.toBeNull(),
908
+ );
909
+ if (mode === "grouped-delayed") {
910
+ await click(
911
+ screen.container.querySelector<HTMLElement>('[data-work-entry-id="tool-near-composer"]')!,
912
+ );
913
+ await vi.waitFor(() => expect(screen.text()).toContain("Loading output"));
914
+ await click(group());
915
+ }
916
+ }
917
+ const header = () => {
918
+ if (mode === "grouped-end")
919
+ return screen.container.querySelector<HTMLElement>(
920
+ '[data-work-entry-id="tool-near-composer"]',
921
+ )!;
922
+ if (mode === "grouped-delayed")
923
+ return screen.container.querySelector<HTMLElement>(
924
+ '[data-timeline-row-kind="work-toggle"] button',
925
+ )!;
926
+ const rows = screen.container.querySelectorAll<HTMLElement>(
927
+ '[data-timeline-row-kind="work"] [role="button"]',
928
+ );
929
+ if (!rows[0]) throw new Error(screen.text());
930
+ return rows[0];
931
+ };
932
+ const visibleBottom = () => viewport.getBoundingClientRect().bottom - composerOverlayHeight;
933
+ await act(() => {
934
+ void props.listRef.current!.scrollToIndex({ index: 6, animated: false });
935
+ });
936
+ if (mode === "at-end") {
937
+ await act(() => {
938
+ void props.listRef.current!.scrollToEnd({ animated: false });
939
+ });
940
+ await vi.waitFor(() =>
941
+ expect(resolveTimelineIsAtEnd(props.listRef.current!.getState())).toBe(true),
942
+ );
943
+ } else {
944
+ await vi.waitFor(async () => {
945
+ await act(() => {
946
+ viewport.scrollTop += header().getBoundingClientRect().bottom - (visibleBottom() - 8);
947
+ viewport.dispatchEvent(new Event("scroll"));
948
+ });
949
+ expect(resolveTimelineIsAtEnd(props.listRef.current!.getState())).toBe(false);
950
+ expect(header().getBoundingClientRect().bottom).toBeLessThanOrEqual(visibleBottom());
951
+ expect(header().getBoundingClientRect().top).toBeGreaterThan(
952
+ viewport.getBoundingClientRect().top,
953
+ );
954
+ });
955
+ }
956
+
957
+ const collapsedScrollTop = viewport.scrollTop;
958
+ using scrollBy = vi.spyOn(viewport, "scrollBy");
959
+ // The nested row can measure before the outer scroller gains its new range.
960
+ if (mode === "grouped-delayed") scrollBy.mockImplementationOnce(() => {});
961
+ await click(header());
962
+ if (mode === "grouped-delayed") {
963
+ await vi.waitFor(() => expect(scrollBy).toHaveBeenCalled());
964
+ outerGrowth = true;
965
+ await screen.rerender(timeline());
966
+ await vi.waitFor(() => expect(viewport.scrollTop).toBeGreaterThan(collapsedScrollTop));
967
+ }
968
+ if (!inline && mode !== "grouped-end") {
969
+ await vi.waitFor(() =>
970
+ expect(header().getBoundingClientRect().bottom).toBeLessThanOrEqual(visibleBottom() + 1),
971
+ );
972
+ await vi.waitFor(() => expect(screen.text()).toContain("Loading output"));
973
+ environmentQuery.data = {
974
+ output: { text: `${"output line\n".repeat(20)}TOOL_INPUT_END`, truncated: false },
975
+ running: false,
976
+ };
977
+ await screen.rerender(timeline());
978
+ }
979
+ const inputEnd = () =>
980
+ Array.from(screen.container.querySelectorAll<HTMLElement>("*")).findLast((element) =>
981
+ element.textContent?.includes("TOOL_INPUT_END"),
982
+ )!;
983
+ await vi.waitFor(() =>
984
+ expect(inputEnd().getBoundingClientRect().bottom).toBeLessThanOrEqual(visibleBottom() + 1),
985
+ );
986
+ await vi.waitFor(() =>
987
+ expect(header().getBoundingClientRect().top).toBeGreaterThanOrEqual(
988
+ viewport.getBoundingClientRect().top,
989
+ ),
990
+ );
991
+ });
992
});
993
994
function usageLimitEntries(resetAt: string) {
apps/web/src/components/chat/MessagesTimeline.tsx
+96
-3
@@ -69,6 +69,7 @@ import {
69
readTimelinePosition,
70
type RememberedTimelinePosition,
71
rememberTimelinePosition,
72
+ resolveDisclosureRevealScrollDelta,
73
} from "./timelineScrollAnchoring";
74
import { AssistantSelectionToolbar } from "./AssistantSelectionToolbar";
75
import type { AssistantCitationSourceAnchor } from "~/lib/assistantTextSelection";
@@ -470,14 +471,80 @@ const ConversationTimeline = memo(function ConversationTimeline({
471
const normalizedFindQuery = findQuery.trim();
472
const findActive = findExpanded;
473
473
- const preserveDisclosurePosition = (anchorKey: string) => {
474
+ const disclosureRevealRef = useRef<{
475
+ key: string;
476
+ identity: string;
477
+ entryId: string | undefined;
478
+ contentKey: string | undefined;
479
+ ready: boolean;
480
+ } | null>(null);
481
+ const disclosureRevealFrameRef = useRef<number | null>(null);
482
+
483
+ // Anchoring keeps the toggled row still, so content that expands below it
484
+ // near the bottom would otherwise land under the composer.
485
+ const revealExpandedDisclosure = useStableCallback(() => {
486
+ const pending = disclosureRevealRef.current;
487
+ if (!pending || pending.identity !== listIdentityKey) return;
488
+ const state = listRef.current?.getState();
489
+ const element = listRef.current?.getScrollableNode();
490
+ const index = state?.indexByKey(pending.key);
491
+ const row = index === undefined ? undefined : state?.elementAtIndex(index);
492
+ if (!element || !(row instanceof HTMLElement)) return;
493
+ const viewport = element.getBoundingClientRect();
494
+ const entry = pending.entryId
495
+ ? row.querySelector<HTMLElement>(`[data-work-entry-id="${CSS.escape(pending.entryId)}"]`)
496
+ : null;
497
+ const contentIndex = pending.contentKey ? state?.indexByKey(pending.contentKey) : undefined;
498
+ const content = contentIndex === undefined ? null : state?.elementAtIndex(contentIndex);
499
+ const bounds = (entry ?? row).getBoundingClientRect();
500
+ const delta = resolveDisclosureRevealScrollDelta({
501
+ rowTop: bounds.top,
502
+ rowBottom: content?.getBoundingClientRect().bottom ?? bounds.bottom,
503
+ viewportTop: viewport.top,
504
+ viewportBottom: viewport.bottom,
505
+ composerOverlayHeight: contentInsetEndAdjustment,
506
+ anchorOffset: CHAT_TIMELINE_ANCHOR_OFFSET,
507
+ });
508
+ // Nested lists can finish measuring before their height reaches the outer scroller.
509
+ if (pending.ready && element.scrollTop + delta <= element.scrollHeight - element.clientHeight) {
510
+ disclosureRevealRef.current = null;
511
+ }
512
+ if (delta > 0) {
513
+ element.scrollBy({ top: delta, behavior: prefersReducedMotion ? "auto" : "smooth" });
514
+ }
515
+ });
516
+ const scheduleDisclosureReveal = () => {
517
+ if (disclosureRevealFrameRef.current !== null) {
518
+ cancelAnimationFrame(disclosureRevealFrameRef.current);
519
+ }
520
+ disclosureRevealFrameRef.current = requestAnimationFrame(() => {
521
+ disclosureRevealFrameRef.current = null;
522
+ revealExpandedDisclosure();
523
+ });
524
+ };
525
+
526
+ const preserveDisclosurePosition = (
527
+ anchorKey: string,
528
+ reveal?: { readonly entryId?: string | undefined; readonly contentKey?: string | undefined },
529
+ ) => {
530
const list = listRef.current;
531
+ disclosureRevealRef.current = null;
532
// An anchor ends end-follow until the reader scrolls, so a streaming turn keeps the live end.
533
if (!list || (isWorking && list.getState().isFollowingEnd)) return;
534
+ if (reveal) {
535
+ disclosureRevealRef.current = {
536
+ key: anchorKey,
537
+ identity: listIdentityKey,
538
+ entryId: reveal.entryId,
539
+ contentKey: reveal.contentKey,
540
+ ready: false,
541
+ };
542
+ }
543
list.cancelScroll();
544
list.anchorVisibleContent({ key: anchorKey });
545
};
546
547
+ // Turn and attempt folds reveal later rows rather than growing their own row.
548
const onToggleTurnFold = (runId: RunId) => {
549
preserveDisclosurePosition(`turn-fold:${runId}`);
550
setExpandedRunIds((existing) => {
@@ -491,7 +558,10 @@ const ConversationTimeline = memo(function ConversationTimeline({
558
});
559
};
560
const onToggleWorkGroup = (groupId: string, anchorKey: string) => {
494
- preserveDisclosurePosition(anchorKey);
561
+ preserveDisclosurePosition(
562
+ anchorKey,
563
+ expandedWorkGroupIds.has(groupId) ? undefined : { contentKey: `${groupId}:details` },
564
+ );
565
setExpandedWorkGroupIds((existing) => {
566
const next = new Set(existing);
567
if (next.has(groupId)) {
@@ -1039,7 +1109,21 @@ const ConversationTimeline = memo(function ConversationTimeline({
1109
onToggleTurnFold,
1110
onToggleAttemptFold,
1111
onToggleWorkGroup,
1042
- onToggleWorkEntry: preserveDisclosurePosition,
1112
+ onToggleWorkEntry: (anchorKey, collapsed, entryId) =>
1113
+ preserveDisclosurePosition(anchorKey, collapsed ? undefined : { entryId }),
1114
+ onWorkEntryContentReady: (anchorKey, entryId) => {
1115
+ const pending = disclosureRevealRef.current;
1116
+ if (
1117
+ !pending ||
1118
+ pending.identity !== listIdentityKey ||
1119
+ (pending.contentKey === undefined
1120
+ ? pending.key !== anchorKey || pending.entryId !== entryId
1121
+ : pending.contentKey !== anchorKey)
1122
+ )
1123
+ return;
1124
+ pending.ready = pending.contentKey === undefined;
1125
+ scheduleDisclosureReveal();
1126
+ },
1127
onCancelWorktreeSetup: onCancelWorktreeSetup ?? null,
1128
retryableWorkspacePreparationRunIds,
1129
onRetryWorkspacePreparation: onRetryWorkspacePreparation ?? null,
@@ -1139,6 +1223,9 @@ const ConversationTimeline = memo(function ConversationTimeline({
1223
viewportRef.current = viewport;
1224
const detachViewport = viewport ? onViewportAttach?.(viewport) : undefined;
1225
const stopRememberingRelease = viewport?.onFollowReleased(rememberReleasedPosition);
1226
+ const stopDisclosureReveal = viewport?.subscribe(() => {
1227
+ disclosureRevealRef.current = null;
1228
+ });
1229
let contentSizeFrame: number | null = null;
1230
// LegendList lays rows out from layout effects; the next frame sees them settled.
1231
let scheduledData: unknown = null;
@@ -1153,6 +1240,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
1240
contentSizeFrame = requestAnimationFrame(() => {
1241
contentSizeFrame = null;
1242
handleContentSizeChanged(laidOutData);
1243
+ revealExpandedDisclosure();
1244
});
1245
};
1246
const stopListeningToContentSize = list
@@ -1162,7 +1250,12 @@ const ConversationTimeline = memo(function ConversationTimeline({
1250
return () => {
1251
stopListeningToContentSize?.();
1252
stopRememberingRelease?.();
1253
+ stopDisclosureReveal?.();
1254
if (contentSizeFrame !== null) cancelAnimationFrame(contentSizeFrame);
1255
+ if (disclosureRevealFrameRef.current !== null) {
1256
+ cancelAnimationFrame(disclosureRevealFrameRef.current);
1257
+ disclosureRevealFrameRef.current = null;
1258
+ }
1259
detachViewport?.();
1260
viewport?.dispose();
1261
if (viewportRef.current === viewport) viewportRef.current = null;
apps/web/src/components/chat/TimelineWorkEntryRow.tsx
+9
-1
@@ -148,6 +148,7 @@ type WorkEntryRowProps = {
148
workspaceRoot: string | undefined;
149
displayLabel?: string | undefined;
150
onToggleEntry?: ((collapsed: boolean) => void) | undefined;
151
+ onContentReady?: (() => void) | undefined;
152
};
153
154
export const SimpleWorkEntryRow = memo(function SimpleWorkEntryRow(props: WorkEntryRowProps) {
@@ -221,10 +222,14 @@ function WorkEntryLogRow(props: WorkEntryRowProps) {
222
const [expanded, setExpanded] = useState(
223
() => groupView?.state.expandedEntries.has(workEntry.id) ?? false,
224
);
225
+ const onInitialOutputReady = () => {
226
+ if (groupView) groupView.onContentReady?.(workEntry.id);
227
+ else props.onContentReady?.();
228
+ };
229
const toggleExpanded = () => {
230
const next = !expanded;
231
if (groupView) {
227
- groupView.onToggleEntry(!next);
232
+ groupView.onToggleEntry(!next, workEntry.id);
233
if (next) groupView.state.expandedEntries.add(workEntry.id);
234
else groupView.state.expandedEntries.delete(workEntry.id);
235
} else {
@@ -430,6 +435,7 @@ function WorkEntryLogRow(props: WorkEntryRowProps) {
435
436
return (
437
<WorkLogRow
438
+ data-work-entry-id={workEntry.id}
439
data-v2-item-type={workEntry.projectedItem?.item.type}
440
data-v2-item-visibility={workEntry.projectedItem?.visibility}
441
{...rowToggleProps}
@@ -570,6 +576,7 @@ function WorkEntryLogRow(props: WorkEntryRowProps) {
576
<WorkLogDetails kind="panel">
577
{workEntry.projectedItem && plainOutput === undefined ? (
578
<V2ItemInspector
579
+ onInitialOutputReady={onInitialOutputReady}
580
projectedItem={workEntry.projectedItem}
581
environmentId={ctx.activeThreadEnvironmentId}
582
cwd={ctx.markdownCwd}
@@ -585,6 +592,7 @@ function WorkEntryLogRow(props: WorkEntryRowProps) {
592
) : null}
593
{plainOutputFetches && workEntry.projectedItem ? (
594
<FetchedToolOutput
595
+ onInitialOutputReady={onInitialOutputReady}
596
projectedItem={workEntry.projectedItem}
597
environmentId={ctx.activeThreadEnvironmentId}
598
onImageExpand={onImageExpand}
apps/web/src/components/chat/TimelineWorkGroupRows.tsx
+19
-7
@@ -68,10 +68,13 @@ export const WorkGroupSection = memo(function WorkGroupSection({
68
isExpandedToolGroup: boolean;
69
displayLabel?: string | undefined;
70
}) {
71
- const { workspaceRoot, routeThreadKey, onToggleWorkEntry, pendingApprovals } =
72
- use(TimelineRowCtx);
73
- const onToggleStandaloneEntry = (collapsed: boolean) =>
74
- onToggleWorkEntry(disclosureAnchorKey, collapsed);
71
+ const {
72
+ workspaceRoot,
73
+ routeThreadKey,
74
+ onToggleWorkEntry,
75
+ onWorkEntryContentReady,
76
+ pendingApprovals,
77
+ } = use(TimelineRowCtx);
78
const nonEmptyEntries = groupedEntries.filter((entry) => {
79
const item = entry.projectedItem?.item;
80
return (
@@ -104,7 +107,10 @@ export const WorkGroupSection = memo(function WorkGroupSection({
107
workEntry={workEntry}
108
workspaceRoot={workspaceRoot}
109
displayLabel={displayLabel}
107
- onToggleEntry={onToggleStandaloneEntry}
110
+ onToggleEntry={(collapsed) =>
111
+ onToggleWorkEntry(disclosureAnchorKey, collapsed, workEntry.id)
112
+ }
113
+ onContentReady={() => onWorkEntryContentReady?.(disclosureAnchorKey, workEntry.id)}
114
/>
115
))}
116
</section>
@@ -133,7 +139,11 @@ function ExpandedWorkGroupEntries({
139
entries: TimelineWorkEntry[];
140
workspaceRoot: string | undefined;
141
}) {
136
- const { workGroupViewState: viewState, onToggleWorkEntry } = use(TimelineRowCtx);
142
+ const {
143
+ workGroupViewState: viewState,
144
+ onToggleWorkEntry,
145
+ onWorkEntryContentReady,
146
+ } = use(TimelineRowCtx);
147
const [initialScrollIndex] = useState(() =>
148
resolveWorkGroupScrollIndex(entries, viewState.scrollPositions.get(anchorKey)),
149
);
@@ -155,7 +165,9 @@ function ExpandedWorkGroupEntries({
165
166
const groupView = {
167
state: viewState,
158
- onToggleEntry: (collapsed: boolean) => onToggleWorkEntry(disclosureAnchorKey, collapsed),
168
+ onToggleEntry: (collapsed: boolean, entryId: string) =>
169
+ onToggleWorkEntry(disclosureAnchorKey, collapsed, entryId),
170
+ onContentReady: (entryId: string) => onWorkEntryContentReady?.(disclosureAnchorKey, entryId),
171
};
172
const updateScrollFades = () => {
173
const element = listRef.current?.getScrollableNode();
apps/web/src/components/chat/V2ItemInspector.tsx
+6
-1
@@ -27,9 +27,10 @@ import { CommandOutputPanel, useCommandOutputStreaming } from "./CommandOutputPa
27
import { resolveExternalWebLinkHref } from "./externalLinkContextMenu";
28
import type { ExpandedImagePreview } from "./ExpandedImagePreview";
29
import { ShellCommandBlock } from "./ShellCommandBlock";
30
-import type { TurnItemSource } from "./timelineRowContext";
30
+import { useInitialOutputReady, type TurnItemSource } from "./timelineRowContext";
31
32
interface V2ItemInspectorProps {
33
+ readonly onInitialOutputReady?: (() => void) | undefined;
34
readonly projectedItem: OrchestrationV2ProjectedTurnItem;
35
readonly environmentId: EnvironmentId;
36
readonly cwd?: string | undefined;
@@ -167,12 +168,14 @@ function ToolOutput(props: ToolOutputState) {
168
}
169
170
export function FetchedToolOutput(props: {
171
+ readonly onInitialOutputReady?: (() => void) | undefined;
172
readonly projectedItem: OrchestrationV2ProjectedTurnItem;
173
readonly environmentId: EnvironmentId;
174
readonly onImageExpand?: ((preview: ExpandedImagePreview) => void) | undefined;
175
readonly source?: TurnItemSource | undefined;
176
}) {
177
const { output } = useFetchedTurnItem(props.projectedItem, props.environmentId, props.source);
178
+ useInitialOutputReady(output.pending, props.onInitialOutputReady);
179
return (
180
<div className={cn("mt-1.5 space-y-1.5", monoClassName)}>
181
<ToolOutputImages {...output} onImageExpand={props.onImageExpand} />
@@ -237,6 +240,7 @@ export const V2ItemInspector = memo(function V2ItemInspector(props: V2ItemInspec
240
);
241
const item = fetched.item;
242
const outputState = fetched.output;
243
+ useInitialOutputReady(streamsOutput || outputState.pending, props.onInitialOutputReady);
244
return (
245
<div className="space-y-2 text-xs" data-v2-item-inspector={item.type}>
246
{item.type === "reasoning" && item.text ? (
@@ -262,6 +266,7 @@ export const V2ItemInspector = memo(function V2ItemInspector(props: V2ItemInspec
266
outputSlot={
267
streamsOutput ? (
268
<CommandOutputPanel
269
+ onInitialOutputReady={props.onInitialOutputReady}
270
environmentId={props.environmentId}
271
threadId={props.projectedItem.sourceThreadId}
272
itemId={props.projectedItem.sourceItemId}
apps/web/src/components/chat/timelineRowContext.ts
+16
-3
@@ -18,7 +18,7 @@ import {
18
import type { AsyncResult, Atom } from "effect/reactivity";
19
import type { CommandOutputView } from "@t3tools/client-runtime/state/command-output";
20
import type { WorkflowOpening } from "@t3tools/client-runtime/state/subagentRuntime";
21
-import { createContext, type MouseEvent, type ReactNode } from "react";
21
+import { useEffect, useRef, createContext, type MouseEvent, type ReactNode } from "react";
22
import { type LegendListRef } from "@legendapp/list/react";
23
import type { CodexArtifactTemplate } from "@t3tools/shared/codexArtifactTemplates";
24
import type { PendingApproval } from "../../session-logic";
@@ -90,7 +90,8 @@ export interface TimelineRowSharedState {
90
onFileDownload: (attachment: ChatFileAttachment) => void;
91
openPullRequest: (event: MouseEvent<HTMLElement>, url: string) => void;
92
onToggleWorkGroup: (groupId: string, anchorKey: string) => void;
93
- onToggleWorkEntry: (anchorKey: string, collapsed: boolean) => void;
93
+ onToggleWorkEntry: (anchorKey: string, collapsed: boolean, entryId?: string) => void;
94
+ onWorkEntryContentReady?: (anchorKey: string, entryId: string) => void;
95
onCancelWorktreeSetup: (() => void) | null;
96
retryableWorkspacePreparationRunIds: ReadonlySet<RunId>;
97
onRetryWorkspacePreparation: ((runId: RunId) => void) | null;
@@ -121,7 +122,8 @@ export interface WorkGroupViewState {
122
123
export const WorkGroupViewCtx = createContext<{
124
state: WorkGroupViewState;
124
- onToggleEntry: (collapsed: boolean) => void;
125
+ onToggleEntry: (collapsed: boolean, entryId: string) => void;
126
+ onContentReady?: ((entryId: string) => void) | undefined;
127
} | null>(null);
128
129
export type TimelineWorkEntry = Extract<
@@ -130,3 +132,14 @@ export type TimelineWorkEntry = Extract<
132
>["groupedEntries"][number];
133
134
export type TimelineRow = MessagesTimelineRow;
135
+
136
+export function useInitialOutputReady(pending: boolean, onReady: (() => void) | undefined) {
137
+ const notified = useRef(false);
138
+ // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- reveals a disclosure after its first async output commits
139
+ useEffect(() => {
140
+ if (!pending && !notified.current) {
141
+ notified.current = true;
142
+ onReady?.();
143
+ }
144
+ }, [pending, onReady]);
145
+}
apps/web/src/components/chat/timelineScrollAnchoring.test.tsx
+34
-1
@@ -1,6 +1,6 @@
1
import { MessageId, RunId } from "@t3tools/contracts";
2
import { describe, expect, it } from "vite-plus/test";
3
-import { observeTimelineRun } from "./timelineScrollAnchoring";
3
+import { observeTimelineRun, resolveDisclosureRevealScrollDelta } from "./timelineScrollAnchoring";
4
5
describe("observeTimelineRun", () => {
6
const existing = {
@@ -67,3 +67,36 @@ describe("observeTimelineRun", () => {
67
);
68
});
69
});
70
+
71
+describe("resolveDisclosureRevealScrollDelta", () => {
72
+ const viewport = {
73
+ viewportTop: 0,
74
+ viewportBottom: 800,
75
+ composerOverlayHeight: 150,
76
+ anchorOffset: 24,
77
+ };
78
+
79
+ it("does not scroll when the expanded row ends above the composer", () => {
80
+ expect(resolveDisclosureRevealScrollDelta({ ...viewport, rowTop: 300, rowBottom: 650 })).toBe(
81
+ 0,
82
+ );
83
+ });
84
+
85
+ it("scrolls content hidden behind the composer into view", () => {
86
+ expect(resolveDisclosureRevealScrollDelta({ ...viewport, rowTop: 560, rowBottom: 900 })).toBe(
87
+ 250,
88
+ );
89
+ });
90
+
91
+ it("keeps the header of a row taller than the usable viewport visible", () => {
92
+ expect(resolveDisclosureRevealScrollDelta({ ...viewport, rowTop: 600, rowBottom: 2000 })).toBe(
93
+ 576,
94
+ );
95
+ });
96
+
97
+ it("never scrolls backwards when the row header is already above the anchor inset", () => {
98
+ expect(resolveDisclosureRevealScrollDelta({ ...viewport, rowTop: -40, rowBottom: 1200 })).toBe(
99
+ 0,
100
+ );
101
+ });
102
+});
apps/web/src/components/chat/timelineScrollAnchoring.ts
+21
@@ -91,6 +91,27 @@ export function timelineContentOverflowsViewport(
91
return lastBottom > visibleScrollLength;
92
}
93
94
+export function resolveDisclosureRevealScrollDelta({
95
+ rowTop,
96
+ rowBottom,
97
+ viewportTop,
98
+ viewportBottom,
99
+ composerOverlayHeight,
100
+ anchorOffset,
101
+}: {
102
+ readonly rowTop: number;
103
+ readonly rowBottom: number;
104
+ readonly viewportTop: number;
105
+ readonly viewportBottom: number;
106
+ readonly composerOverlayHeight: number;
107
+ readonly anchorOffset: number;
108
+}): number {
109
+ const hiddenBelow = rowBottom - (viewportBottom - composerOverlayHeight);
110
+ if (!(hiddenBelow > 0)) return 0;
111
+ const roomAbove = rowTop - (viewportTop + anchorOffset);
112
+ return Math.max(0, Math.min(hiddenBelow, roomAbove));
113
+}
114
+
115
export interface RememberedTimelinePosition {
116
readonly rowId: string;
117
readonly offsetWithinRow: number;