@devries-cameron20 / t3code Mirror · read-only / commits / 8d012a688e
Fork 0

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 22, 12:00 UTC

fix(web): a new thread's first reply shows without reloading (#27522)

Julius Marminge committed Oct 30, 2026 at 10:08 UTC 8d012a688e7cb12fb17a91be68a32734a0efa0b7
4 files changed +70 -2
apps/web/src/components/ChatView.browser.test.tsx new
+64
@@ -0,0 +1,64 @@
1 +import { createMemoryHistory } from "@tanstack/react-router";
2 +import { scopeProjectRef } from "@t3tools/client-runtime/environment";
3 +import { ThreadId } from "@t3tools/contracts";
4 +import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings";
5 +import type * as Context from "effect/Context";
6 +import { expect, it, vi } from "vite-plus/test";
7 +import { page } from "vite-plus/test/browser";
8 +
9 +import { AppRoot } from "~/AppRoot";
10 +import { DraftId, useComposerDraftStore } from "~/composerDraftStore";
11 +import { __setClientSettingsForTests } from "~/hooks/useSettings";
12 +import { getRouter } from "~/router";
13 +import {
14 + ENVIRONMENT_ID,
15 + PROJECT_ID,
16 + installFakeEnvironment,
17 + type FakeDriver,
18 +} from "../../test/fakeEnvironment";
19 +import { render } from "../../test/render";
20 +
21 +// The socket is the only fake layer; see test/appScenarios.renders.tsx.
22 +vi.mock("../../../../packages/client-runtime/src/connection/driver.ts", async (importOriginal) => {
23 + const [actual, { fakeDriver }, Layer] = await Promise.all([
24 + importOriginal<{ readonly ConnectionDriver: Context.Key<unknown, FakeDriver> }>(),
25 + import("../../test/fakeEnvironment"),
26 + import("effect/Layer"),
27 + ]);
28 + return { ...actual, layer: Layer.succeed(actual.ConnectionDriver, fakeDriver) };
29 +});
30 +
31 +vi.mock(import("~/rpc/requestLatencyState"), async (original) => ({
32 + ...(await original()),
33 + trackRpcRequestSent: () => {},
34 +}));
35 +
36 +it("a new draft does not load its reserved thread before the server lists it", async () => {
37 + using _environment = installFakeEnvironment([]);
38 + using fetchSpy = vi.spyOn(globalThis, "fetch");
39 + __setClientSettingsForTests({
40 + ...DEFAULT_CLIENT_SETTINGS,
41 + onboardingCompletedAt: "2026-01-01T00:00:00.000Z",
42 + });
43 + const draftId = DraftId.make("draft-27443");
44 + const threadId = ThreadId.make("thread-27443");
45 + useComposerDraftStore
46 + .getState()
47 + .setProjectDraftThreadId(scopeProjectRef(ENVIRONMENT_ID, PROJECT_ID), draftId, { threadId });
48 +
49 + const router = getRouter(createMemoryHistory({ initialEntries: [`/draft/${draftId}`] }));
50 + await router.load();
51 + await using _app = await render(<AppRoot router={router} />, {
52 + // AppRoot brings its own router.
53 + router: false,
54 + });
55 + await expect.element(page.getByTestId("composer-editor")).toBeVisible();
56 + // The shell snapshot has arrived once the sidebar lists the project, so the connection is up.
57 + await expect.element(page.getByText("render", { exact: true }).first()).toBeVisible();
58 +
59 + const threadRequests = fetchSpy.mock.calls
60 + .map(([input]) => String(input instanceof Request ? input.url : input))
61 + .filter((url) => url.includes(`/api/orchestration/threads/${threadId}/`));
62 + // A 404 here marks the thread deleted, and the view never loads it once the send creates it.
63 + expect(threadRequests).toEqual([]);
64 +});
apps/web/src/components/ChatView.tsx
+1
@@ -2376,6 +2376,7 @@ export default function ChatView(props: ChatViewProps) {
2376 activeThread,
2377 activeThreadId,
2378 activeThreadRef,
2379 + threadDetailRef: routeThreadDetailRef,
2380 activeThreadKey,
2381 activeThreadShell,
2382 activeLatestRun,
apps/web/src/components/chat/useThreadLifecycle.tsx
+4 -1
@@ -87,6 +87,8 @@ interface ThreadLifecycleInput {
87 readonly activeThread: EnvironmentThreadShell | undefined;
88 readonly activeThreadId: ThreadId | null;
89 readonly activeThreadRef: ScopedThreadRef | null;
90 + /** Null until the thread's detail may load; see resolveThreadDetailRef. */
91 + readonly threadDetailRef: ScopedThreadRef | null;
92 readonly activeThreadKey: string | null;
93 readonly activeThreadShell: EnvironmentThreadShell | null;
94 readonly activeLatestRun: EnvironmentThreadShell["latestRun"];
@@ -138,6 +140,7 @@ export function useThreadLifecycle(input: ThreadLifecycleInput) {
140 activeThread,
141 activeThreadId,
142 activeThreadRef,
143 + threadDetailRef,
144 activeThreadKey,
145 activeThreadShell,
146 activeLatestRun,
@@ -524,7 +527,7 @@ export function useThreadLifecycle(input: ThreadLifecycleInput) {
527
528 const forceStop = useForceStopThread(environmentId);
529 const anyRunStop = useAtomValue(
527 - activeThreadRef ? environmentThreadDetails.runStopAtom(activeThreadRef) : NO_RUN_STOP_ATOM,
530 + threadDetailRef ? environmentThreadDetails.runStopAtom(threadDetailRef) : NO_RUN_STOP_ATOM,
531 );
532 // A background Stop matters only while that work is still pending.
533 const runStop = anyRunStop?.background && activeBackgroundTasks.length === 0 ? null : anyRunStop;
apps/web/test/fakeEnvironment.ts
+1 -1
@@ -44,7 +44,7 @@ import * as Stream from "effect/Stream";
44 import { RpcSchema } from "effect/rpc";
45
46 export const ENVIRONMENT_ID = EnvironmentId.make("environment-render");
47 -const PROJECT_ID = ProjectId.make("project-render");
47 +export const PROJECT_ID = ProjectId.make("project-render");
48 const CODEX = ProviderInstanceId.make("codex");
49 const MODEL = { instanceId: CODEX, model: "gpt-5.4" };
50 const AT = DateTime.makeUnsafe("2026-03-17T19:12:28.000Z");