Skip to content

Commit a702563

Browse files
perf(web): the new-thread handler keeps its identity across provider pushes (pingdotgg#20731)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 3cb1330 commit a702563

2 files changed

Lines changed: 24 additions & 15 deletions

File tree

‎apps/web/src/hooks/useHandleNewThread.test.ts‎

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,29 @@ const testState = vi.hoisted(() => {
7979
};
8080
});
8181

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+
82100
vi.mock("@effect/atom-react", () => ({
83101
useAtomValue: (atom: unknown) =>
84102
atom === "primary-settings"
85103
? { 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(),
98105
}));
99106
vi.mock("@t3tools/client-runtime/environment", () => ({
100107
scopedProjectKey: () => "remote-project",

‎apps/web/src/hooks/useHandleNewThread.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { useAtomValue } from "@effect/atom-react";
21
import {
32
scopedProjectKey,
43
scopeProjectRef,
@@ -37,6 +36,7 @@ import {
3736
resolveNewThreadModelSelectionOverride,
3837
} from "../lib/chatThreadActions";
3938
import { readT3ProjectFile } from "../lib/t3ProjectFileDefaults";
39+
import { appAtomRegistry } from "../rpc/atomRegistry";
4040
import { environmentServerConfigsAtom } from "../state/server";
4141
import { resolveThreadRouteTarget } from "../threadRoutes";
4242
import { legacyProjectCwdPreferenceKey, useUiStateStore } from "../uiStateStore";
@@ -59,7 +59,6 @@ function pickExplicitWorkspaceOptions(options: NewThreadWorkspaceOptions | undef
5959
}
6060

6161
export function useNewThreadHandler() {
62-
const environmentServerConfigs = useAtomValue(environmentServerConfigsAtom);
6362
const projectGroupingSettings = useClientSettings(selectProjectGroupingSettings);
6463
const router = useRouter();
6564
const getCurrentRouteTarget = useCallback(() => {
@@ -79,6 +78,9 @@ export function useNewThreadHandler() {
7978
},
8079
): Promise<{ draftId: DraftId; threadId: ThreadId } | null> => {
8180
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);
8284
const targetServerSettings =
8385
environmentServerConfigs.get(projectRef.environmentId)?.settings ?? DEFAULT_SERVER_SETTINGS;
8486
const {
@@ -386,7 +388,7 @@ export function useNewThreadHandler() {
386388
return { draftId, threadId };
387389
})();
388390
},
389-
[environmentServerConfigs, getCurrentRouteTarget, projectGroupingSettings, router],
391+
[getCurrentRouteTarget, projectGroupingSettings, router],
390392
);
391393
}
392394

0 commit comments

Comments
 (0)