Skip to content

Commit afd8367

Browse files
committed
fix(web): reveal delayed output when reopening work groups
1 parent e1a044a commit afd8367

5 files changed

Lines changed: 67 additions & 12 deletions

File tree

‎apps/web/src/components/chat/MessagesTimeline.browser.test.tsx‎

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ describe("MessagesTimeline messages", () => {
392392
expect((globalThis as { __t3Xss?: number }).__t3Xss).toBeUndefined();
393393
});
394394

395-
it.each(["inline", "delayed"])("handles %s output expanded above the composer", async (mode) => {
395+
it.each(["inline", "delayed", "grouped-delayed"])("reveals %s output", async (mode) => {
396396
setup();
397397
environmentQuery.data = null;
398398
environmentQuery.error = null;
@@ -446,14 +446,61 @@ describe("MessagesTimeline messages", () => {
446446
}),
447447
},
448448
},
449+
...(mode === "grouped-delayed"
450+
? [
451+
{
452+
id: "another-tool",
453+
kind: "work" as const,
454+
createdAt: CREATED_AT,
455+
entry: {
456+
id: "another-tool",
457+
createdAt: CREATED_AT,
458+
label: "Other tool",
459+
tone: "tool" as const,
460+
itemType: "dynamic_tool" as const,
461+
toolLifecycleStatus: "completed" as const,
462+
toolData: { input: { query: "other" } },
463+
},
464+
},
465+
]
466+
: []),
449467
...tallEntries.slice(6),
450468
]}
451469
/>
452470
);
453471
await using screen = await renderElement(timeline());
454472
await vi.waitFor(() => expect(props.listRef.current?.getScrollableNode()).toBeTruthy());
455473
const viewport = props.listRef.current!.getScrollableNode()!;
474+
if (mode === "grouped-delayed") {
475+
await act(() => {
476+
void props.listRef.current!.scrollToIndex({ index: 6, animated: false });
477+
});
478+
await vi.waitFor(() =>
479+
expect(
480+
screen.container.querySelector('[data-timeline-row-kind="work-toggle"] button'),
481+
).not.toBeNull(),
482+
);
483+
const group = () =>
484+
screen.container.querySelector<HTMLElement>(
485+
'[data-timeline-row-kind="work-toggle"] button',
486+
)!;
487+
await click(group());
488+
await vi.waitFor(() =>
489+
expect(
490+
screen.container.querySelector('[data-work-entry-id="tool-near-composer"]'),
491+
).not.toBeNull(),
492+
);
493+
await click(
494+
screen.container.querySelector<HTMLElement>('[data-work-entry-id="tool-near-composer"]')!,
495+
);
496+
await vi.waitFor(() => expect(screen.text()).toContain("Loading output"));
497+
await click(group());
498+
}
456499
const header = () => {
500+
if (mode === "grouped-delayed")
501+
return screen.container.querySelector<HTMLElement>(
502+
'[data-timeline-row-kind="work-toggle"] button',
503+
)!;
457504
const rows = screen.container.querySelectorAll<HTMLElement>(
458505
'[data-timeline-row-kind="work"] [role="button"]',
459506
);
@@ -475,7 +522,11 @@ describe("MessagesTimeline messages", () => {
475522
);
476523
});
477524

525+
const collapsedScrollTop = viewport.scrollTop;
478526
await click(header());
527+
if (mode === "grouped-delayed") {
528+
await vi.waitFor(() => expect(viewport.scrollTop).toBeGreaterThan(collapsedScrollTop));
529+
}
479530
if (mode !== "inline") {
480531
await vi.waitFor(() =>
481532
expect(header().getBoundingClientRect().bottom).toBeLessThanOrEqual(visibleBottom() + 1),

‎apps/web/src/components/chat/MessagesTimeline.tsx‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,12 +1094,14 @@ const ConversationTimeline = memo(function ConversationTimeline({
10941094
onWorkEntryContentReady: (anchorKey, entryId) => {
10951095
const pending = disclosureRevealRef.current;
10961096
if (
1097-
pending?.key !== anchorKey ||
1098-
pending.entryId !== entryId ||
1099-
pending.identity !== listIdentityKey
1097+
!pending ||
1098+
pending.identity !== listIdentityKey ||
1099+
(pending.contentKey === undefined
1100+
? pending.key !== anchorKey || pending.entryId !== entryId
1101+
: pending.contentKey !== anchorKey)
11001102
)
11011103
return;
1102-
pending.ready = true;
1104+
pending.ready = pending.contentKey === undefined;
11031105
scheduleDisclosureSettle();
11041106
},
11051107
onCancelWorktreeSetup: onCancelWorktreeSetup ?? null,

‎apps/web/src/components/chat/TimelineWorkGroupRows.tsx‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,13 @@ export const WorkGroupSection = memo(function WorkGroupSection({
6767
isExpandedToolGroup: boolean;
6868
displayLabel?: string | undefined;
6969
}) {
70-
const { workspaceRoot, routeThreadKey, onToggleWorkEntry, onWorkEntryContentReady, pendingApprovals } =
71-
use(TimelineRowCtx);
70+
const {
71+
workspaceRoot,
72+
routeThreadKey,
73+
onToggleWorkEntry,
74+
onWorkEntryContentReady,
75+
pendingApprovals,
76+
} = use(TimelineRowCtx);
7277
const nonEmptyEntries = groupedEntries.filter((entry) => {
7378
const item = entry.projectedItem?.item;
7479
return (

‎apps/web/src/components/chat/timelineRowContext.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export type TimelineRow = MessagesTimelineRow;
134134

135135
export function useInitialOutputReady(pending: boolean, onReady: (() => void) | undefined) {
136136
const notified = useRef(false);
137-
// oxlint-disable-next-line t3code/react-effect-budget -- reveals a disclosure after its first async output commits
137+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- reveals a disclosure after its first async output commits
138138
useEffect(() => {
139139
if (!pending && !notified.current) {
140140
notified.current = true;

‎apps/web/src/components/chat/timelineScrollAnchoring.test.tsx‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { MessageId, RunId } from "@t3tools/contracts";
22
import { describe, expect, it } from "vite-plus/test";
3-
import {
4-
observeTimelineRun,
5-
resolveDisclosureRevealScrollDelta,
6-
} from "./timelineScrollAnchoring";
3+
import { observeTimelineRun, resolveDisclosureRevealScrollDelta } from "./timelineScrollAnchoring";
74

85
describe("observeTimelineRun", () => {
96
const existing = {

0 commit comments

Comments
 (0)