The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 15:30 UTC
fix(web): keep thread links open until the shell is live (#14697)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Alex Southwell committed
Oct 11, 2026 at 14:31 UTC
6c130163941618480da333979bf6fc675d803e4f
3 files changed
+51
-8
apps/web/src/components/ThreadRouteView.tsx
+2
-1
@@ -19,6 +19,7 @@ import { useEnvironmentQuery } from "../state/query";
19
import { environmentShell } from "../state/shell";
20
import {
21
buildThreadRouteParams,
22
+ isThreadRouteSnapshotAuthoritative,
23
resolveThreadRouteRenderState,
24
type ThreadRouteTarget,
25
} from "../threadRoutes";
@@ -72,7 +73,7 @@ export function ThreadRouteView({ target }: { target: ThreadRouteTarget }) {
73
);
74
const serverThreadShell = serverThread;
75
const environmentThreadRefs = useEnvironmentThreadRefs(serverThreadRef?.environmentId ?? null);
75
- const bootstrapComplete = shell.data?.snapshot._tag === "Some";
76
+ const bootstrapComplete = isThreadRouteSnapshotAuthoritative(shell.data?.status);
77
const draftThread = useComposerDraftStore((store) =>
78
serverThreadRef ? store.getDraftThreadByRef(serverThreadRef) : null,
79
);
apps/web/src/threadRoutes.test.ts
+38
@@ -6,6 +6,7 @@ import { DraftId } from "./composerDraftStore";
6
import {
7
buildDraftThreadRouteParams,
8
buildThreadRouteParams,
9
+ isThreadRouteSnapshotAuthoritative,
10
resolveActiveThreadRouteRef,
11
resolveThreadRouteRenderState,
12
resolveThreadRouteRef,
@@ -13,6 +14,13 @@ import {
14
} from "./threadRoutes";
15
16
describe("threadRoutes", () => {
17
+ it("does not treat cached thread lists as authoritative for deep links", () => {
18
+ expect(isThreadRouteSnapshotAuthoritative("empty")).toBe(false);
19
+ expect(isThreadRouteSnapshotAuthoritative("cached")).toBe(false);
20
+ expect(isThreadRouteSnapshotAuthoritative("synchronizing")).toBe(false);
21
+ expect(isThreadRouteSnapshotAuthoritative("live")).toBe(true);
22
+ });
23
+
24
it("builds canonical thread route params from a scoped ref", () => {
25
const ref = scopeThreadRef("env-1" as never, ThreadId.make("thread-1"));
26
@@ -124,6 +132,25 @@ describe("threadRoutes", () => {
132
).toBe("ready");
133
});
134
135
+ it.each([
136
+ { status: "cached", source: "server thread" },
137
+ { status: "synchronizing", source: "server thread" },
138
+ { status: "cached", source: "draft" },
139
+ { status: "synchronizing", source: "draft" },
140
+ ] as const)(
141
+ "keeps available $source visible while the shell is $status",
142
+ ({ status, source }) => {
143
+ expect(
144
+ resolveThreadRouteRenderState({
145
+ bootstrapComplete: isThreadRouteSnapshotAuthoritative(status),
146
+ serverThreadExists: source === "server thread",
147
+ serverThreadDeleted: false,
148
+ draftThreadExists: source === "draft",
149
+ }),
150
+ ).toBe("ready");
151
+ },
152
+ );
153
+
154
it("distinguishes bootstrap loading from a missing thread", () => {
155
expect(
156
resolveThreadRouteRenderState({
@@ -153,4 +180,15 @@ describe("threadRoutes", () => {
180
}),
181
).toBe("missing");
182
});
183
+
184
+ it("waits for the live shell before redirecting a deleted thread", () => {
185
+ expect(
186
+ resolveThreadRouteRenderState({
187
+ bootstrapComplete: isThreadRouteSnapshotAuthoritative("cached"),
188
+ serverThreadExists: true,
189
+ serverThreadDeleted: true,
190
+ draftThreadExists: false,
191
+ }),
192
+ ).toBe("loading");
193
+ });
194
});
apps/web/src/threadRoutes.ts
+11
-7
@@ -1,4 +1,5 @@
1
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
2
+import type { EnvironmentShellStatus } from "@t3tools/client-runtime/state/shell";
3
import type { EnvironmentId, ScopedThreadRef, ThreadId } from "@t3tools/contracts";
4
import type { DraftId } from "./composerDraftStore";
5
@@ -20,22 +21,25 @@ type DraftThreadRouteState = {
21
22
export type ThreadRouteRenderState = "loading" | "ready" | "missing";
23
24
+export function isThreadRouteSnapshotAuthoritative(
25
+ status: EnvironmentShellStatus | undefined,
26
+): boolean {
27
+ return status === "live";
28
+}
29
+
30
export function resolveThreadRouteRenderState(input: {
31
bootstrapComplete: boolean;
32
serverThreadExists: boolean;
33
serverThreadDeleted: boolean;
34
draftThreadExists: boolean;
35
}): ThreadRouteRenderState {
29
- if (!input.bootstrapComplete) {
30
- return "loading";
31
- }
32
- if (input.draftThreadExists) {
36
+ if (input.draftThreadExists || (input.serverThreadExists && !input.serverThreadDeleted)) {
37
return "ready";
38
}
35
- if (input.serverThreadDeleted) {
36
- return "missing";
39
+ if (!input.bootstrapComplete) {
40
+ return "loading";
41
}
38
- return input.serverThreadExists ? "ready" : "missing";
42
+ return "missing";
43
}
44
45
export function buildThreadRouteParams(ref: ScopedThreadRef): {