The best way to control Claude Code, Codex and more from any computer or phone
fix(web): opening a just-created thread no longer bounces to the start page (#19724)
Co-authored-by: FranzCh <28222983+Fr4nzz@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
FranzCh committed
Oct 20, 2026 at 00:11 UTC
ab638a6e0d6a3742107839f6faeec79523012ca7
4 files changed
+174
-4
apps/web/src/components/ChatView.tsx
+46
-3
@@ -88,6 +88,7 @@ import {
88
import { readPastedComposerContext } from "./composerInlineTokenPaste";
89
import { isPasteAsTextShortcut } from "@t3tools/client-runtime/text-paste";
90
import { effectiveSnoozed, threadWokeAt } from "@t3tools/client-runtime/state/thread-settled";
91
+import { presentThreadShell } from "@t3tools/client-runtime/state/shell";
92
import { childThreadInputsTitle } from "@t3tools/client-runtime/state/threads";
93
import { useAcknowledgeThreadWoke, useThreadActions } from "../hooks/useThreadActions";
94
import {
@@ -1120,13 +1121,55 @@ export default function ChatView(props: ChatViewProps) {
1121
? store.getDraftSession(draftId)
1122
: null,
1123
);
1123
- const serverThread = useQuietThreadShell(routeThreadRef);
1124
+ const serverThreadShell = useQuietThreadShell(routeThreadRef);
1125
const routeThreadDetailRef = resolveThreadDetailRef(routeThreadRef, {
1125
- shellExists: serverThread !== null,
1126
+ shellExists: serverThreadShell !== null,
1127
waitForShell: draftThread !== null,
1128
});
1129
const serverThreadProjection = useThreadProjection(routeThreadDetailRef);
1130
const serverProjection = serverThreadProjection?.projection ?? null;
1131
+ const serverThread = (() => {
1132
+ if (serverThreadShell !== null || serverProjection === null) {
1133
+ return serverThreadShell;
1134
+ }
1135
+ const latestRun = deriveLatestThreadRun(serverProjection);
1136
+ const runtime = deriveThreadRuntime(serverProjection);
1137
+ const pendingRuntimeRequest =
1138
+ serverProjection.runtimeRequests.findLast((request) => request.status === "pending") ?? null;
1139
+ // Direct links can hydrate detail before the thread enters the shell index.
1140
+ return {
1141
+ ...presentThreadShell(environmentId, {
1142
+ ...serverProjection.thread,
1143
+ latestRunId: latestRun?.runId ?? null,
1144
+ activeRunId: runtime?.activeRunId ?? null,
1145
+ status: runtime?.status ?? "idle",
1146
+ pendingRuntimeRequest,
1147
+ latestVisibleMessage: null,
1148
+ latestUserMessageAt:
1149
+ serverProjection.messages.findLast((message) => message.role === "user")?.updatedAt ??
1150
+ null,
1151
+ hasActionableProposedPlan: serverProjection.plans.some(
1152
+ (plan) => plan.kind === "proposed_plan" && plan.status === "active",
1153
+ ),
1154
+ providerInstanceHistory: [
1155
+ ...new Set(
1156
+ serverProjection.providerThreads
1157
+ .filter((thread) => thread.appThreadId === threadId && thread.ownerNodeId === null)
1158
+ .map((thread) => thread.providerInstanceId),
1159
+ ),
1160
+ ],
1161
+ goal:
1162
+ serverProjection.providerThreads.find(
1163
+ (thread) => thread.id === serverProjection.thread.activeProviderThreadId,
1164
+ )?.goal ?? null,
1165
+ itemCount: serverProjection.turnItems.length,
1166
+ visibleItemCount: serverProjection.visibleTurnItems.length,
1167
+ updatedAt: serverProjection.updatedAt,
1168
+ }),
1169
+ latestRun,
1170
+ runtime,
1171
+ };
1172
+ })();
1173
const promptRef = useRef("");
1174
const localComposerRef = useRef<ChatComposerHandle | null>(null);
1175
const composerRef = useComposerHandleContext() ?? localComposerRef;
@@ -1608,7 +1651,7 @@ export default function ChatView(props: ChatViewProps) {
1651
container: workspaceLayoutElement,
1652
widthStorageKey: `t3code:preview-panel-width:${activeThreadKey}`,
1653
});
1611
- const activeThreadShell = useQuietThreadShell(isServerThread ? activeThreadRef : null);
1654
+ const activeThreadShell = serverThread;
1655
const timelineThreadError =
1656
serverRuntime?.status === "failed" &&
1657
serverRuntime.lastErrorClass === "usage_limit" &&
apps/web/src/components/ThreadRouteView.tsx
+13
@@ -16,6 +16,7 @@ import {
16
import { useSidebarPendingFileDropStore } from "../sidebarPendingFileDropStore";
17
import { useEnvironmentThreadRefs, useThreadRefs, useQuietThreadShell } from "../state/entities";
18
import { useEnvironmentShellStatus } from "../state/shell";
19
+import { useEnvironmentThread } from "../state/threads";
20
import {
21
buildThreadRouteParams,
22
isThreadRouteSnapshotAuthoritative,
@@ -87,10 +88,22 @@ export function ThreadRouteView({ target }: { target: ThreadRouteTarget }) {
88
const environmentHasDraftThreads = useComposerDraftStore((store) =>
89
serverThreadRef ? store.hasDraftThreadsInEnvironment(serverThreadRef.environmentId) : false,
90
);
91
+ // Until the shell lists the thread, its own load (HTTP, then the socket)
92
+ // decides whether it exists. Read only then: once listed, ChatView keeps
93
+ // this stream open and its updates need not re-render the route.
94
+ const unlistedThreadRef =
95
+ target.kind === "server" && serverThreadShell === null && draftThread === null
96
+ ? target.threadRef
97
+ : null;
98
+ const unlistedThreadDetail = useEnvironmentThread(
99
+ unlistedThreadRef?.environmentId ?? null,
100
+ unlistedThreadRef?.threadId ?? null,
101
+ );
102
const renderState = resolveThreadRouteRenderState({
103
bootstrapComplete,
104
serverThreadExists: serverThreadShell !== null,
105
serverThreadDeleted: serverThreadShell?.deletedAt != null,
106
+ unlistedThreadDetail,
107
draftThreadExists: draftThread !== null,
108
});
109
const serverThreadStarted = threadHasStarted(serverThreadShell);
apps/web/src/threadRoutes.test.ts
+101
@@ -1,7 +1,11 @@
1
import { describe, expect, it } from "vite-plus/test";
2
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
3
+import { EMPTY_ENVIRONMENT_THREAD_STATE } from "@t3tools/client-runtime/state/threads";
4
import { ThreadId } from "@t3tools/contracts";
5
+import * as DateTime from "effect/DateTime";
6
+import * as Option from "effect/Option";
7
import { DraftId } from "./composerDraftStore";
8
+import { makeThreadProjectionFixture } from "./test-fixtures";
9
10
import {
11
buildDraftThreadRouteParams,
@@ -122,6 +126,7 @@ describe("threadRoutes", () => {
126
bootstrapComplete: true,
127
serverThreadExists: true,
128
serverThreadDeleted: false,
129
+ unlistedThreadDetail: EMPTY_ENVIRONMENT_THREAD_STATE,
130
draftThreadExists: false,
131
}),
132
).toBe("ready");
@@ -133,6 +138,7 @@ describe("threadRoutes", () => {
138
bootstrapComplete: true,
139
serverThreadExists: true,
140
serverThreadDeleted: false,
141
+ unlistedThreadDetail: EMPTY_ENVIRONMENT_THREAD_STATE,
142
draftThreadExists: false,
143
}),
144
).toBe("ready");
@@ -141,6 +147,7 @@ describe("threadRoutes", () => {
147
bootstrapComplete: true,
148
serverThreadExists: false,
149
serverThreadDeleted: false,
150
+ unlistedThreadDetail: EMPTY_ENVIRONMENT_THREAD_STATE,
151
draftThreadExists: true,
152
}),
153
).toBe("ready");
@@ -159,6 +166,7 @@ describe("threadRoutes", () => {
166
bootstrapComplete: isThreadRouteSnapshotAuthoritative(status),
167
serverThreadExists: source === "server thread",
168
serverThreadDeleted: false,
169
+ unlistedThreadDetail: EMPTY_ENVIRONMENT_THREAD_STATE,
170
draftThreadExists: source === "draft",
171
}),
172
).toBe("ready");
@@ -171,6 +179,7 @@ describe("threadRoutes", () => {
179
bootstrapComplete: false,
180
serverThreadExists: false,
181
serverThreadDeleted: false,
182
+ unlistedThreadDetail: { ...EMPTY_ENVIRONMENT_THREAD_STATE, status: "deleted" },
183
draftThreadExists: false,
184
}),
185
).toBe("loading");
@@ -179,17 +188,108 @@ describe("threadRoutes", () => {
188
bootstrapComplete: true,
189
serverThreadExists: false,
190
serverThreadDeleted: false,
191
+ unlistedThreadDetail: { ...EMPTY_ENVIRONMENT_THREAD_STATE, status: "deleted" },
192
draftThreadExists: false,
193
}),
194
).toBe("missing");
195
});
196
197
+ it("opens an unlisted server thread once its detail arrives, without waiting for the shell", () => {
198
+ const route = {
199
+ bootstrapComplete: isThreadRouteSnapshotAuthoritative("live"),
200
+ serverThreadExists: false,
201
+ serverThreadDeleted: false,
202
+ draftThreadExists: false,
203
+ };
204
+
205
+ expect(
206
+ resolveThreadRouteRenderState({
207
+ ...route,
208
+ unlistedThreadDetail: EMPTY_ENVIRONMENT_THREAD_STATE,
209
+ }),
210
+ ).toBe("loading");
211
+ expect(
212
+ resolveThreadRouteRenderState({
213
+ ...route,
214
+ unlistedThreadDetail: {
215
+ ...EMPTY_ENVIRONMENT_THREAD_STATE,
216
+ status: "synchronizing",
217
+ },
218
+ }),
219
+ ).toBe("loading");
220
+ expect(
221
+ resolveThreadRouteRenderState({
222
+ ...route,
223
+ unlistedThreadDetail: {
224
+ ...EMPTY_ENVIRONMENT_THREAD_STATE,
225
+ status: "synchronizing",
226
+ error: Option.some("Connection interrupted"),
227
+ },
228
+ }),
229
+ ).toBe("loading");
230
+ expect(
231
+ resolveThreadRouteRenderState({
232
+ ...route,
233
+ unlistedThreadDetail: {
234
+ ...EMPTY_ENVIRONMENT_THREAD_STATE,
235
+ status: "live",
236
+ data: Option.some(makeThreadProjectionFixture()),
237
+ },
238
+ }),
239
+ ).toBe("ready");
240
+ });
241
+
242
+ it.each(["missing", "deleted", "archived"] as const)(
243
+ "redirects an unlisted thread only after detail confirms it is %s",
244
+ (outcome) => {
245
+ const route = {
246
+ bootstrapComplete: isThreadRouteSnapshotAuthoritative("live"),
247
+ serverThreadExists: false,
248
+ serverThreadDeleted: false,
249
+ draftThreadExists: false,
250
+ };
251
+ expect(
252
+ resolveThreadRouteRenderState({
253
+ ...route,
254
+ unlistedThreadDetail: {
255
+ ...EMPTY_ENVIRONMENT_THREAD_STATE,
256
+ status: "synchronizing",
257
+ },
258
+ }),
259
+ ).toBe("loading");
260
+
261
+ const projection = makeThreadProjectionFixture();
262
+ const removedAt = DateTime.makeUnsafe("2026-01-02T00:00:00Z");
263
+ expect(
264
+ resolveThreadRouteRenderState({
265
+ ...route,
266
+ unlistedThreadDetail:
267
+ outcome === "missing"
268
+ ? { ...EMPTY_ENVIRONMENT_THREAD_STATE, status: "deleted" }
269
+ : {
270
+ ...EMPTY_ENVIRONMENT_THREAD_STATE,
271
+ status: "live",
272
+ data: Option.some({
273
+ ...projection,
274
+ thread: {
275
+ ...projection.thread,
276
+ deletedAt: outcome === "deleted" ? removedAt : null,
277
+ archivedAt: outcome === "archived" ? removedAt : null,
278
+ },
279
+ }),
280
+ },
281
+ }),
282
+ ).toBe("missing");
283
+ },
284
+ );
285
+
286
it("redirects deleted server threads", () => {
287
expect(
288
resolveThreadRouteRenderState({
289
bootstrapComplete: true,
290
serverThreadExists: true,
291
serverThreadDeleted: true,
292
+ unlistedThreadDetail: EMPTY_ENVIRONMENT_THREAD_STATE,
293
draftThreadExists: false,
294
}),
295
).toBe("missing");
@@ -201,6 +301,7 @@ describe("threadRoutes", () => {
301
bootstrapComplete: isThreadRouteSnapshotAuthoritative("cached"),
302
serverThreadExists: true,
303
serverThreadDeleted: true,
304
+ unlistedThreadDetail: EMPTY_ENVIRONMENT_THREAD_STATE,
305
draftThreadExists: false,
306
}),
307
).toBe("loading");
apps/web/src/threadRoutes.ts
+14
-1
@@ -1,6 +1,8 @@
1
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
2
import type { EnvironmentShellStatus } from "@t3tools/client-runtime/state/shell";
3
+import type { EnvironmentThreadState } from "@t3tools/client-runtime/state/threads";
4
import type { EnvironmentId, ScopedThreadRef, ThreadId } from "@t3tools/contracts";
5
+import * as Option from "effect/Option";
6
import type { DraftId } from "./composerDraftStore";
7
8
export type ThreadRouteTarget =
@@ -31,6 +33,7 @@ export function resolveThreadRouteRenderState(input: {
33
bootstrapComplete: boolean;
34
serverThreadExists: boolean;
35
serverThreadDeleted: boolean;
36
+ unlistedThreadDetail: EnvironmentThreadState;
37
draftThreadExists: boolean;
38
}): ThreadRouteRenderState {
39
if (input.draftThreadExists || (input.serverThreadExists && !input.serverThreadDeleted)) {
@@ -39,7 +42,17 @@ export function resolveThreadRouteRenderState(input: {
42
if (!input.bootstrapComplete) {
43
return "loading";
44
}
42
- return "missing";
45
+ if (input.serverThreadExists || input.unlistedThreadDetail.status === "deleted") {
46
+ return "missing";
47
+ }
48
+ // Shell membership can lag a new thread; its detail decides.
49
+ const projection = Option.getOrNull(input.unlistedThreadDetail.data);
50
+ if (projection === null) {
51
+ return "loading";
52
+ }
53
+ return projection.thread.deletedAt !== null || projection.thread.archivedAt !== null
54
+ ? "missing"
55
+ : "ready";
56
}
57
58
export function buildThreadRouteParams(ref: ScopedThreadRef): {