| author | |
| committer | |
| log | 6c130163941618480da333979bf6fc675d803e4f |
| tree | 35391e4ade6dca235d0cdc5c7fee07f4bb03c000 |
| parent | 5ce5a8f658b229c36fc4dc371bb4dc4157500c00 |
| signature | Signed by PGP key B5690EEEBB952194 |
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>3 files changed, 51 insertions(+), 8 deletions(-)
apps/web/src/components/ThreadRouteView.tsx+2-1| ... | ... | @@ -19,6 +19,7 @@ import { useEnvironmentQuery } from "../state/query"; |
| 19 | 19 | import { environmentShell } from "../state/shell"; |
| 20 | 20 | import { |
| 21 | 21 | buildThreadRouteParams, |
| 22 | isThreadRouteSnapshotAuthoritative, | |
| 22 | 23 | resolveThreadRouteRenderState, |
| 23 | 24 | type ThreadRouteTarget, |
| 24 | 25 | } from "../threadRoutes"; |
| ... | ... | @@ -72,7 +73,7 @@ export function ThreadRouteView({ target }: { target: ThreadRouteTarget }) { |
| 72 | 73 | ); |
| 73 | 74 | const serverThreadShell = serverThread; |
| 74 | 75 | const environmentThreadRefs = useEnvironmentThreadRefs(serverThreadRef?.environmentId ?? null); |
| 75 | const bootstrapComplete = shell.data?.snapshot._tag === "Some"; | |
| 76 | const bootstrapComplete = isThreadRouteSnapshotAuthoritative(shell.data?.status); | |
| 76 | 77 | const draftThread = useComposerDraftStore((store) => |
| 77 | 78 | serverThreadRef ? store.getDraftThreadByRef(serverThreadRef) : null, |
| 78 | 79 | ); |
apps/web/src/threadRoutes.test.ts+38| ... | ... | @@ -6,6 +6,7 @@ import { DraftId } from "./composerDraftStore"; |
| 6 | 6 | import { |
| 7 | 7 | buildDraftThreadRouteParams, |
| 8 | 8 | buildThreadRouteParams, |
| 9 | isThreadRouteSnapshotAuthoritative, | |
| 9 | 10 | resolveActiveThreadRouteRef, |
| 10 | 11 | resolveThreadRouteRenderState, |
| 11 | 12 | resolveThreadRouteRef, |
| ... | ... | @@ -13,6 +14,13 @@ import { |
| 13 | 14 | } from "./threadRoutes"; |
| 14 | 15 | |
| 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 | ||
| 16 | 24 | it("builds canonical thread route params from a scoped ref", () => { |
| 17 | 25 | const ref = scopeThreadRef("env-1" as never, ThreadId.make("thread-1")); |
| 18 | 26 | |
| ... | ... | @@ -124,6 +132,25 @@ describe("threadRoutes", () => { |
| 124 | 132 | ).toBe("ready"); |
| 125 | 133 | }); |
| 126 | 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 | ||
| 127 | 154 | it("distinguishes bootstrap loading from a missing thread", () => { |
| 128 | 155 | expect( |
| 129 | 156 | resolveThreadRouteRenderState({ |
| ... | ... | @@ -153,4 +180,15 @@ describe("threadRoutes", () => { |
| 153 | 180 | }), |
| 154 | 181 | ).toBe("missing"); |
| 155 | 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 | }); | |
| 156 | 194 | }); |
apps/web/src/threadRoutes.ts+11-7| ... | ... | @@ -1,4 +1,5 @@ |
| 1 | 1 | import { scopeThreadRef } from "@t3tools/client-runtime/environment"; |
| 2 | import type { EnvironmentShellStatus } from "@t3tools/client-runtime/state/shell"; | |
| 2 | 3 | import type { EnvironmentId, ScopedThreadRef, ThreadId } from "@t3tools/contracts"; |
| 3 | 4 | import type { DraftId } from "./composerDraftStore"; |
| 4 | 5 | |
| ... | ... | @@ -20,22 +21,25 @@ type DraftThreadRouteState = { |
| 20 | 21 | |
| 21 | 22 | export type ThreadRouteRenderState = "loading" | "ready" | "missing"; |
| 22 | 23 | |
| 24 | export function isThreadRouteSnapshotAuthoritative( | |
| 25 | status: EnvironmentShellStatus | undefined, | |
| 26 | ): boolean { | |
| 27 | return status === "live"; | |
| 28 | } | |
| 29 | ||
| 23 | 30 | export function resolveThreadRouteRenderState(input: { |
| 24 | 31 | bootstrapComplete: boolean; |
| 25 | 32 | serverThreadExists: boolean; |
| 26 | 33 | serverThreadDeleted: boolean; |
| 27 | 34 | draftThreadExists: boolean; |
| 28 | 35 | }): ThreadRouteRenderState { |
| 29 | if (!input.bootstrapComplete) { | |
| 30 | return "loading"; | |
| 31 | } | |
| 32 | if (input.draftThreadExists) { | |
| 36 | if (input.draftThreadExists || (input.serverThreadExists && !input.serverThreadDeleted)) { | |
| 33 | 37 | return "ready"; |
| 34 | 38 | } |
| 35 | if (input.serverThreadDeleted) { | |
| 36 | return "missing"; | |
| 39 | if (!input.bootstrapComplete) { | |
| 40 | return "loading"; | |
| 37 | 41 | } |
| 38 | return input.serverThreadExists ? "ready" : "missing"; | |
| 42 | return "missing"; | |
| 39 | 43 | } |
| 40 | 44 | |
| 41 | 45 | export function buildThreadRouteParams(ref: ScopedThreadRef): { |