Skip to content

Commit 252b32b

Browse files
fix(web): resolve held-timeline markdown against the painted thread cwd
Relative links were still opening against the destination thread while the previous list stayed on screen. Store cwd with the snapshot and use it for that paint-only interval. Co-authored-by: Julius Marminge <[email protected]>
1 parent 6c3f8ec commit 252b32b

3 files changed

Lines changed: 51 additions & 16 deletions

File tree

‎apps/web/src/components/ChatView.logic.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,19 @@ describe("resolveThreadSwitchTimeline", () => {
612612
).toEqual({ entries: [], displayThreadKey: "env-1:thread-a" });
613613
});
614614

615+
it("keeps the held thread workspace cwd with the snapshot", () => {
616+
rememberReadyThreadTimeline({
617+
...held,
618+
markdownCwd: "/repo/a",
619+
workspaceRoot: "/repo/a",
620+
});
621+
expect(peekHeldThreadTimeline<string[]>()).toEqual({
622+
...held,
623+
markdownCwd: "/repo/a",
624+
workspaceRoot: "/repo/a",
625+
});
626+
});
627+
615628
it("survives a ChatView remount by remembering the last ready timeline", () => {
616629
rememberReadyThreadTimeline(held);
617630
expect(peekHeldThreadTimeline<string[]>()).toEqual(held);

‎apps/web/src/components/ChatView.logic.ts‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -277,27 +277,32 @@ export function resolveDraftHeroState(input: {
277277
export type HeldThreadTimeline<T extends readonly unknown[]> = {
278278
threadKey: string | null;
279279
entries: T;
280+
markdownCwd?: string | null;
281+
workspaceRoot?: string | null;
280282
};
281283

282284
const MAX_REMEMBERED_THREAD_TIMELINES = 16;
283285

284-
let rememberedThreadTimelines = new Map<string, readonly unknown[]>();
286+
let rememberedThreadTimelines = new Map<string, HeldThreadTimeline<readonly unknown[]>>();
285287
let rememberedThreadTimelineOrder: string[] = [];
286288
let lastReadyThreadKey: string | null = null;
287289

288-
function rememberThreadTimelineEntries(threadKey: string, entries: readonly unknown[]): void {
289-
rememberedThreadTimelines.set(threadKey, entries);
290+
function rememberThreadTimelineEntries(held: HeldThreadTimeline<readonly unknown[]>): void {
291+
if (held.threadKey === null) {
292+
return;
293+
}
294+
rememberedThreadTimelines.set(held.threadKey, held);
290295
rememberedThreadTimelineOrder = [
291-
...rememberedThreadTimelineOrder.filter((key) => key !== threadKey),
292-
threadKey,
296+
...rememberedThreadTimelineOrder.filter((key) => key !== held.threadKey),
297+
held.threadKey,
293298
];
294299
while (rememberedThreadTimelineOrder.length > MAX_REMEMBERED_THREAD_TIMELINES) {
295300
const evicted = rememberedThreadTimelineOrder.shift();
296301
if (evicted !== undefined) {
297302
rememberedThreadTimelines.delete(evicted);
298303
}
299304
}
300-
lastReadyThreadKey = threadKey;
305+
lastReadyThreadKey = held.threadKey;
301306
}
302307

303308
export function rememberReadyThreadTimeline<T extends readonly unknown[]>(
@@ -306,7 +311,7 @@ export function rememberReadyThreadTimeline<T extends readonly unknown[]>(
306311
if (held.threadKey === null || held.entries.length === 0) {
307312
return;
308313
}
309-
rememberThreadTimelineEntries(held.threadKey, held.entries);
314+
rememberThreadTimelineEntries(held);
310315
}
311316

312317
export function peekRememberedThreadTimeline<T extends readonly unknown[]>(
@@ -315,7 +320,7 @@ export function peekRememberedThreadTimeline<T extends readonly unknown[]>(
315320
if (threadKey === null) {
316321
return null;
317322
}
318-
return (rememberedThreadTimelines.get(threadKey) as T | undefined) ?? null;
323+
return (rememberedThreadTimelines.get(threadKey)?.entries as T | undefined) ?? null;
319324
}
320325

321326
export function peekHeldThreadTimeline<
@@ -324,11 +329,11 @@ export function peekHeldThreadTimeline<
324329
if (lastReadyThreadKey === null) {
325330
return null;
326331
}
327-
const entries = rememberedThreadTimelines.get(lastReadyThreadKey);
328-
if (entries === undefined || entries.length === 0) {
332+
const held = rememberedThreadTimelines.get(lastReadyThreadKey);
333+
if (held === undefined || held.entries.length === 0) {
329334
return null;
330335
}
331-
return { threadKey: lastReadyThreadKey, entries: entries as T };
336+
return held as HeldThreadTimeline<T>;
332337
}
333338

334339
export function resetHeldThreadTimeline(): void {

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ import {
416416
resolveComposerProviderSelection,
417417
resolveDraftHeroState,
418418
isPaintOnlyThreadTimeline,
419+
peekHeldThreadTimeline,
419420
peekRememberedThreadTimeline,
420421
rememberReadyThreadTimeline,
421422
resolveThreadSwitchTimeline,
@@ -3247,9 +3248,6 @@ export default function ChatView(props: ChatViewProps) {
32473248
timelineMessages,
32483249
workLogEntries,
32493250
]);
3250-
if (!threadDetailLoading && timelineEntries.length > 0) {
3251-
rememberReadyThreadTimeline({ threadKey: activeThreadKey, entries: timelineEntries });
3252-
}
32533251
const displayedTimeline = resolveThreadSwitchTimeline({
32543252
loading: timelineEntries.length === 0 && threadSyncPhase !== null,
32553253
activeThreadKey,
@@ -3360,6 +3358,17 @@ export default function ChatView(props: ChatViewProps) {
33603358
const activeProjectCwd = activeProject?.workspaceRoot ?? null;
33613359
const activeThreadWorktreePath = activeThread?.worktreePath ?? null;
33623360
const activeWorkspaceRoot = activeThreadWorktreePath ?? activeProjectCwd ?? undefined;
3361+
if (!threadDetailLoading && timelineEntries.length > 0) {
3362+
rememberReadyThreadTimeline({
3363+
threadKey: activeThreadKey,
3364+
entries: timelineEntries,
3365+
markdownCwd: gitCwd,
3366+
workspaceRoot: activeWorkspaceRoot ?? null,
3367+
});
3368+
}
3369+
const heldPaintContext = paintOnlyDisplayedTimeline
3370+
? peekHeldThreadTimeline<typeof timelineEntries>()
3371+
: null;
33633372
const activeTerminalLaunchContext =
33643373
terminalUiLaunchContext?.threadId === activeThreadId ? terminalUiLaunchContext : null;
33653374
// Git status arrives after the composer paints. A checkout seen earlier in
@@ -8443,10 +8452,18 @@ export default function ChatView(props: ChatViewProps) {
84438452
onFileDownload={
84448453
paintOnlyDisplayedTimeline ? noopHeldAttachment : downloadFileAttachment
84458454
}
8446-
markdownCwd={gitCwd ?? undefined}
8455+
markdownCwd={
8456+
paintOnlyDisplayedTimeline
8457+
? (heldPaintContext?.markdownCwd ?? undefined)
8458+
: (gitCwd ?? undefined)
8459+
}
84478460
resolvedTheme={resolvedTheme}
84488461
timestampFormat={timestampFormat}
8449-
workspaceRoot={activeWorkspaceRoot}
8462+
workspaceRoot={
8463+
paintOnlyDisplayedTimeline
8464+
? (heldPaintContext?.workspaceRoot ?? undefined)
8465+
: activeWorkspaceRoot
8466+
}
84508467
skills={
84518468
activeProviderStatus
84528469
? resolveProviderSkillsForCwd(activeProviderStatus, gitCwd)

0 commit comments

Comments
 (0)