Skip to content

Commit 7dd91b5

Browse files
fix(web): preserve thread shell while details sync
- Keep thread metadata visible during message loading - Show sync status and disable composer until details are ready
1 parent 2905925 commit 7dd91b5

12 files changed

Lines changed: 245 additions & 177 deletions

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

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import {
88
} from "@t3tools/contracts";
99
import { describe, expect, it } from "vite-plus/test";
1010

11-
import type { Thread } from "../types";
11+
import type { Thread, ThreadShell } from "../types";
1212
import {
1313
MAX_HIDDEN_MOUNTED_PREVIEW_THREADS,
1414
MAX_HIDDEN_MOUNTED_TERMINAL_THREADS,
1515
branchMismatchKey,
1616
buildExpiredTerminalContextToastCopy,
17+
buildLoadingThreadFromShell,
1718
buildThreadTurnInterruptInput,
1819
createLocalDispatchSnapshot,
1920
deriveComposerSendState,
@@ -85,6 +86,51 @@ const readySession = {
8586
updatedAt: "2026-03-29T00:00:10.000Z",
8687
};
8788

89+
describe("buildLoadingThreadFromShell", () => {
90+
it("preserves shell metadata and supplies empty detail collections", () => {
91+
const shell = {
92+
environmentId,
93+
id: threadId,
94+
projectId,
95+
title: "Loading thread",
96+
modelSelection: {
97+
instanceId: ProviderInstanceId.make("codex"),
98+
model: "gpt-5.4",
99+
},
100+
runtimeMode: "full-access",
101+
interactionMode: "default",
102+
branch: "main",
103+
worktreePath: null,
104+
latestTurn: null,
105+
createdAt: now,
106+
updatedAt: now,
107+
archivedAt: null,
108+
settledOverride: null,
109+
settledAt: null,
110+
snoozedUntil: null,
111+
snoozedAt: null,
112+
session: null,
113+
latestUserMessageAt: now,
114+
hasPendingApprovals: false,
115+
hasPendingUserInput: false,
116+
hasActionableProposedPlan: false,
117+
} satisfies ThreadShell;
118+
119+
expect(buildLoadingThreadFromShell(shell)).toMatchObject({
120+
environmentId,
121+
id: threadId,
122+
projectId,
123+
title: "Loading thread",
124+
branch: "main",
125+
deletedAt: null,
126+
messages: [],
127+
proposedPlans: [],
128+
activities: [],
129+
checkpoints: [],
130+
});
131+
});
132+
});
133+
88134
describe("resolveThreadMetadataUpdateForNextTurn", () => {
89135
const modelSelection = {
90136
instanceId: ProviderInstanceId.make("codex"),

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
type ThreadId,
1111
type TurnId,
1212
} from "@t3tools/contracts";
13-
import { type ChatMessage, type SessionPhase, type Thread } from "../types";
13+
import { type ChatMessage, type SessionPhase, type Thread, type ThreadShell } from "../types";
1414
import { type ComposerImageAttachment, type DraftThreadState } from "../composerDraftStore";
1515
import * as Schema from "effect/Schema";
1616
import { appAtomRegistry } from "../rpc/atomRegistry";
@@ -95,6 +95,17 @@ export function buildLocalDraftThread(
9595
};
9696
}
9797

98+
export function buildLoadingThreadFromShell(shell: ThreadShell): Thread {
99+
return {
100+
...shell,
101+
messages: [],
102+
proposedPlans: [],
103+
activities: [],
104+
checkpoints: [],
105+
deletedAt: null,
106+
};
107+
}
108+
98109
export function shouldWriteThreadErrorToCurrentServerThread(input: {
99110
serverThread:
100111
| {

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ import {
238238
import { ThreadErrorBanner } from "./chat/ThreadErrorBanner";
239239
import { resolveThreadPr } from "./ThreadStatusIndicators";
240240
import { ComposerBannerStack, type ComposerBannerStackItem } from "./chat/ComposerBannerStack";
241+
import { ThreadSyncStatusPill } from "./chat/ThreadSyncStatusPill";
241242
import {
242243
DRAFT_HERO_TRANSITION_ANIMATION_ID,
243244
DRAFT_HERO_TRANSITION_DURATION_MS,
@@ -251,6 +252,7 @@ import {
251252
branchMismatchKey,
252253
buildExpiredTerminalContextToastCopy,
253254
buildLocalDraftThread,
255+
buildLoadingThreadFromShell,
254256
buildThreadTurnInterruptInput,
255257
collectUserMessageBlobPreviewUrls,
256258
createLocalDispatchSnapshot,
@@ -275,6 +277,7 @@ import {
275277
startNewThreadForProject,
276278
waitForStartedServerThread,
277279
} from "./ChatView.logic";
280+
import type { ThreadSyncPhase } from "../threadSync";
278281
import { useLocalStorage } from "~/hooks/useLocalStorage";
279282
import { useComposerHandleContext } from "../composerHandleContext";
280283
import { sanitizeThreadErrorMessage } from "~/rpc/transportError";
@@ -465,6 +468,7 @@ type ChatViewProps =
465468
onDiffPanelOpen?: () => void;
466469
reserveTitleBarControlInset?: boolean;
467470
forceExpandedMobileComposer?: boolean;
471+
threadSyncPhase?: ThreadSyncPhase | null;
468472
routeKind: "server";
469473
draftId?: never;
470474
}
@@ -474,6 +478,7 @@ type ChatViewProps =
474478
onDiffPanelOpen?: () => void;
475479
reserveTitleBarControlInset?: boolean;
476480
forceExpandedMobileComposer?: boolean;
481+
threadSyncPhase?: never;
477482
routeKind: "draft";
478483
draftId: DraftId;
479484
};
@@ -1132,6 +1137,8 @@ function ChatViewContent(props: ChatViewProps) {
11321137
forceExpandedMobileComposer = false,
11331138
} = props;
11341139
const draftId = routeKind === "draft" ? props.draftId : null;
1140+
const threadSyncPhase = routeKind === "server" ? (props.threadSyncPhase ?? null) : null;
1141+
const threadDetailLoading = threadSyncPhase === "loading";
11351142
const handleNewThread = useNewThreadHandler();
11361143
const routeThreadRef = useMemo(
11371144
() => scopeThreadRef(environmentId, threadId),
@@ -1188,7 +1195,15 @@ function ChatViewContent(props: ChatViewProps) {
11881195
? store.getDraftSession(draftId)
11891196
: null,
11901197
);
1198+
const routeServerThreadShell = useThreadShell(routeKind === "server" ? routeThreadRef : null);
11911199
const serverThread = useThread(routeThreadRef, { waitForShell: draftThread !== null });
1200+
const loadingServerThread = useMemo(
1201+
() =>
1202+
threadDetailLoading && routeServerThreadShell
1203+
? buildLoadingThreadFromShell(routeServerThreadShell)
1204+
: null,
1205+
[routeServerThreadShell, threadDetailLoading],
1206+
);
11921207
const markThreadVisited = useUiStateStore((store) => store.markThreadVisited);
11931208
const activeThreadLastVisitedAt = useUiStateStore(
11941209
(store) => store.threadLastVisitedAtById[routeThreadKey],
@@ -1421,10 +1436,11 @@ function ChatViewContent(props: ChatViewProps) {
14211436
// Promotion is data-driven: the draft route keeps rendering while the
14221437
// server thread (same pre-allocated ref) starts, so live state must not
14231438
// depend on which route is mounted.
1424-
const isServerThread = serverThread !== null;
1425-
const activeThread = isServerThread ? serverThread : localDraftThread;
1439+
const activeServerThread = serverThread ?? loadingServerThread;
1440+
const isServerThread = activeServerThread !== null;
1441+
const activeThread = activeServerThread ?? localDraftThread;
14261442
const threadError = isServerThread
1427-
? (localServerError ?? serverThread?.session?.lastError ?? null)
1443+
? (localServerError ?? activeServerThread?.session?.lastError ?? null)
14281444
: localDraftError;
14291445
const runtimeMode = composerRuntimeMode ?? activeThread?.runtimeMode ?? DEFAULT_RUNTIME_MODE;
14301446
const interactionMode =
@@ -4471,6 +4487,7 @@ function ChatViewContent(props: ChatViewProps) {
44714487
!activeThread ||
44724488
isSendBusy ||
44734489
isConnecting ||
4490+
threadDetailLoading ||
44744491
activeEnvironmentUnavailable ||
44754492
sendInFlightRef.current
44764493
)
@@ -5737,7 +5754,7 @@ function ChatViewContent(props: ChatViewProps) {
57375754
contentInsetEndAdjustment={composerOverlayHeight}
57385755
onIsAtEndChange={onIsAtEndChange}
57395756
onManualNavigation={cancelTimelineLiveFollowForUserNavigation}
5740-
hideEmptyPlaceholder={isDraftHeroState}
5757+
hideEmptyPlaceholder={isDraftHeroState || threadDetailLoading}
57415758
topFadeEnabled={!hasTimelineTopBanner}
57425759
/>
57435760

@@ -5798,6 +5815,9 @@ function ChatViewContent(props: ChatViewProps) {
57985815
) : (
57995816
<ComposerBannerStack className="relative z-0" items={composerBannerItems} />
58005817
)}
5818+
{threadSyncPhase && !activeEnvironmentUnavailable ? (
5819+
<ThreadSyncStatusPill phase={threadSyncPhase} />
5820+
) : null}
58015821
<div
58025822
className="relative"
58035823
style={
@@ -5831,6 +5851,7 @@ function ChatViewContent(props: ChatViewProps) {
58315851
phase={phase}
58325852
isConnecting={isConnecting}
58335853
isSendBusy={isSendBusy}
5854+
sendDisabledReason={threadDetailLoading ? "Messages loading" : null}
58345855
isPreparingWorktree={isPreparingWorktree}
58355856
environmentUnavailable={activeEnvironmentUnavailableState}
58365857
activePendingApproval={activePendingApproval}

‎apps/web/src/components/ThreadDetailLoadingState.test.tsx‎

Lines changed: 0 additions & 28 deletions
This file was deleted.

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

Lines changed: 0 additions & 115 deletions
This file was deleted.

0 commit comments

Comments
 (0)