1- import { useAtomValue } from "@effect/atom-react" ;
21import {
32 scopedProjectKey ,
43 scopeProjectRef ,
@@ -37,6 +36,7 @@ import {
3736 resolveNewThreadModelSelectionOverride ,
3837} from "../lib/chatThreadActions" ;
3938import { readT3ProjectFile } from "../lib/t3ProjectFileDefaults" ;
39+ import { appAtomRegistry } from "../rpc/atomRegistry" ;
4040import { environmentServerConfigsAtom } from "../state/server" ;
4141import { resolveThreadRouteTarget } from "../threadRoutes" ;
4242import { legacyProjectCwdPreferenceKey , useUiStateStore } from "../uiStateStore" ;
@@ -59,7 +59,6 @@ function pickExplicitWorkspaceOptions(options: NewThreadWorkspaceOptions | undef
5959}
6060
6161export 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