Skip to content

Commit 6c13016

Browse files
saphidgithub-actions[bot]claude
authored
fix(web): keep thread links open until the shell is live (pingdotgg#14697)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 5ce5a8f commit 6c13016

3 files changed

Lines changed: 51 additions & 8 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { useEnvironmentQuery } from "../state/query";
1919
import { environmentShell } from "../state/shell";
2020
import {
2121
buildThreadRouteParams,
22+
isThreadRouteSnapshotAuthoritative,
2223
resolveThreadRouteRenderState,
2324
type ThreadRouteTarget,
2425
} from "../threadRoutes";
@@ -72,7 +73,7 @@ export function ThreadRouteView({ target }: { target: ThreadRouteTarget }) {
7273
);
7374
const serverThreadShell = serverThread;
7475
const environmentThreadRefs = useEnvironmentThreadRefs(serverThreadRef?.environmentId ?? null);
75-
const bootstrapComplete = shell.data?.snapshot._tag === "Some";
76+
const bootstrapComplete = isThreadRouteSnapshotAuthoritative(shell.data?.status);
7677
const draftThread = useComposerDraftStore((store) =>
7778
serverThreadRef ? store.getDraftThreadByRef(serverThreadRef) : null,
7879
);

‎apps/web/src/threadRoutes.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@ import { DraftId } from "./composerDraftStore";
66
import {
77
buildDraftThreadRouteParams,
88
buildThreadRouteParams,
9+
isThreadRouteSnapshotAuthoritative,
910
resolveActiveThreadRouteRef,
1011
resolveThreadRouteRenderState,
1112
resolveThreadRouteRef,
1213
resolveThreadRouteTarget,
1314
} from "./threadRoutes";
1415

1516
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+
1624
it("builds canonical thread route params from a scoped ref", () => {
1725
const ref = scopeThreadRef("env-1" as never, ThreadId.make("thread-1"));
1826

@@ -124,6 +132,25 @@ describe("threadRoutes", () => {
124132
).toBe("ready");
125133
});
126134

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+
127154
it("distinguishes bootstrap loading from a missing thread", () => {
128155
expect(
129156
resolveThreadRouteRenderState({
@@ -153,4 +180,15 @@ describe("threadRoutes", () => {
153180
}),
154181
).toBe("missing");
155182
});
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+
});
156194
});

‎apps/web/src/threadRoutes.ts‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
2+
import type { EnvironmentShellStatus } from "@t3tools/client-runtime/state/shell";
23
import type { EnvironmentId, ScopedThreadRef, ThreadId } from "@t3tools/contracts";
34
import type { DraftId } from "./composerDraftStore";
45

@@ -20,22 +21,25 @@ type DraftThreadRouteState = {
2021

2122
export type ThreadRouteRenderState = "loading" | "ready" | "missing";
2223

24+
export function isThreadRouteSnapshotAuthoritative(
25+
status: EnvironmentShellStatus | undefined,
26+
): boolean {
27+
return status === "live";
28+
}
29+
2330
export function resolveThreadRouteRenderState(input: {
2431
bootstrapComplete: boolean;
2532
serverThreadExists: boolean;
2633
serverThreadDeleted: boolean;
2734
draftThreadExists: boolean;
2835
}): ThreadRouteRenderState {
29-
if (!input.bootstrapComplete) {
30-
return "loading";
31-
}
32-
if (input.draftThreadExists) {
36+
if (input.draftThreadExists || (input.serverThreadExists && !input.serverThreadDeleted)) {
3337
return "ready";
3438
}
35-
if (input.serverThreadDeleted) {
36-
return "missing";
39+
if (!input.bootstrapComplete) {
40+
return "loading";
3741
}
38-
return input.serverThreadExists ? "ready" : "missing";
42+
return "missing";
3943
}
4044

4145
export function buildThreadRouteParams(ref: ScopedThreadRef): {

0 commit comments

Comments
 (0)