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, 08:00 UTC
perf(web): the new-thread handler keeps its identity across provider pushes (#20731)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 16, 2026 at 21:06 UTC
a7025639c0e16aad3081106c935bf3025f601a1e
2 files changed
+24
-15
apps/web/src/hooks/useHandleNewThread.test.ts
+19
-12
@@ -79,22 +79,29 @@ const testState = vi.hoisted(() => {
79
};
80
});
81
82
+const testServerConfigs = () =>
83
+ new Map([
84
+ [
85
+ "environment-primary",
86
+ {
87
+ settings: {
88
+ ...testState.targetSettings,
89
+ newWorktreesStartFromOrigin: !testState.targetSettings.newWorktreesStartFromOrigin,
90
+ },
91
+ },
92
+ ],
93
+ ["environment-ssh", { settings: testState.targetSettings }],
94
+ ]);
95
+
96
+vi.mock("../rpc/atomRegistry", () => ({
97
+ appAtomRegistry: { get: () => testServerConfigs() },
98
+}));
99
+
100
vi.mock("@effect/atom-react", () => ({
101
useAtomValue: (atom: unknown) =>
102
atom === "primary-settings"
103
? { newWorktreesStartFromOrigin: !testState.targetSettings.newWorktreesStartFromOrigin }
86
- : new Map([
87
- [
88
- "environment-primary",
89
- {
90
- settings: {
91
- ...testState.targetSettings,
92
- newWorktreesStartFromOrigin: !testState.targetSettings.newWorktreesStartFromOrigin,
93
- },
94
- },
95
- ],
96
- ["environment-ssh", { settings: testState.targetSettings }],
97
- ]),
104
+ : testServerConfigs(),
105
}));
106
vi.mock("@t3tools/client-runtime/environment", () => ({
107
scopedProjectKey: () => "remote-project",
apps/web/src/hooks/useHandleNewThread.ts
+5
-3
@@ -1,4 +1,3 @@
1
-import { useAtomValue } from "@effect/atom-react";
1
import {
2
scopedProjectKey,
3
scopeProjectRef,
@@ -37,6 +36,7 @@ import {
36
resolveNewThreadModelSelectionOverride,
37
} from "../lib/chatThreadActions";
38
import { readT3ProjectFile } from "../lib/t3ProjectFileDefaults";
39
+import { appAtomRegistry } from "../rpc/atomRegistry";
40
import { environmentServerConfigsAtom } from "../state/server";
41
import { resolveThreadRouteTarget } from "../threadRoutes";
42
import { legacyProjectCwdPreferenceKey, useUiStateStore } from "../uiStateStore";
@@ -59,7 +59,6 @@ function pickExplicitWorkspaceOptions(options: NewThreadWorkspaceOptions | undef
59
}
60
61
export function useNewThreadHandler() {
62
- const environmentServerConfigs = useAtomValue(environmentServerConfigsAtom);
62
const projectGroupingSettings = useClientSettings(selectProjectGroupingSettings);
63
const router = useRouter();
64
const getCurrentRouteTarget = useCallback(() => {
@@ -79,6 +78,9 @@ export function useNewThreadHandler() {
78
},
79
): Promise<{ draftId: DraftId; threadId: ThreadId } | null> => {
80
const projects = readProjects();
81
+ // Read at call time: every provider status push replaces the config map, and
82
+ // subscribing would hand every sidebar row a new handler.
83
+ const environmentServerConfigs = appAtomRegistry.get(environmentServerConfigsAtom);
84
const targetServerSettings =
85
environmentServerConfigs.get(projectRef.environmentId)?.settings ?? DEFAULT_SERVER_SETTINGS;
86
const {
@@ -386,7 +388,7 @@ export function useNewThreadHandler() {
388
return { draftId, threadId };
389
})();
390
},
389
- [environmentServerConfigs, getCurrentRouteTarget, projectGroupingSettings, router],
391
+ [getCurrentRouteTarget, projectGroupingSettings, router],
392
);
393
}
394