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, 05:30 UTC
refactor(web): the thread lineage panel keeps its caching without "use memo" hooks (#20789)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 16, 2026 at 23:26 UTC
583ad66c525b188367f3e70aeed96f32f9b01790
1 file changed
+30
-50
apps/web/src/components/chat/ThreadRelationshipsControl.tsx
+30
-50
@@ -30,7 +30,6 @@ import {
30
NodeId,
31
type EnvironmentId,
32
type OrchestrationV2Subagent,
33
- type OrchestrationV2ThreadProjection,
33
type OrchestrationV2ThreadShell,
34
type ThreadId,
35
} from "@t3tools/contracts";
@@ -205,11 +204,34 @@ function currentSubagent<Agent extends RuntimeSubagent>(
204
};
205
}
206
208
-// These lookups and the graph walk every subagent and thread; the panel calls
209
-// several hooks after them, which would stop the compiler caching them inline.
210
-function useSubagentLookups(subagents: ReadonlyArray<OrchestrationV2Subagent> | undefined) {
211
- "use memo";
212
- const projected = subagents ?? [];
207
+export function ThreadRelationshipsPanel(props: {
208
+ readonly environmentId: EnvironmentId;
209
+ readonly threadId: ThreadId;
210
+}) {
211
+ const ref = scopeThreadRef(props.environmentId, props.threadId);
212
+ const projection = useThreadProjection(ref)?.projection ?? null;
213
+ const serverConfigs = useServerConfigs();
214
+ const threadShells = useThreadShells();
215
+ const allProjects = useProjects();
216
+ const archived = useArchivedThreadSnapshots([props.environmentId]);
217
+ const navigate = useNavigate();
218
+ const mergeBack = useAtomCommand(threadEnvironment.mergeBack);
219
+ const stopSession = useAtomCommand(threadEnvironment.stopSession);
220
+ const interruptTurn = useAtomCommand(threadEnvironment.interruptTurn);
221
+ const stopWorkflowCommand = useAtomCommand(orchestrationEnvironment.stopWorkflow);
222
+ const canOperateWorkflow = useAtomValue(
223
+ orchestrationEnvironment.stopWorkflow.permissionAtom(props.environmentId),
224
+ );
225
+ const [busyAction, setBusyAction] = useState<"merge" | "detach" | null>(null);
226
+ const [stoppingId, setStoppingId] = useState<string | null>(null);
227
+ // These lookups and the graph walk every subagent and thread, so they sit below
228
+ // the panel's hooks where the compiler can cache them.
229
+ const providers = serverConfigs.get(props.environmentId)?.providers;
230
+ const projects = allProjects.filter((project) => project.environmentId === props.environmentId);
231
+ const archivedShells = archived.snapshots.find(
232
+ (entry) => entry.environmentId === props.environmentId,
233
+ )?.snapshot.threads;
234
+ const projected = projection?.subagents ?? [];
235
const runtimeSubagents = projectedSubagentsToRuntime(projected);
236
const byId = new Map(runtimeSubagents.map((agent) => [agent.id, agent]));
237
const subagentsByThreadId = new Map(
@@ -234,57 +256,15 @@ function useSubagentLookups(subagents: ReadonlyArray<OrchestrationV2Subagent> |
256
const workflowGroupsById = new Map(
257
deriveWorkflowGroups(runtimeSubagents).map((group) => [group.workflow.id, group]),
258
);
237
- return { subagentsByThreadId, workflowGroupsById };
238
-}
239
-
240
-function useThreadRelationshipGraph(
241
- threadShells: ReturnType<typeof useThreadShells>,
242
- archivedShells: ReadonlyArray<OrchestrationV2ThreadShell> | undefined,
243
- projection: OrchestrationV2ThreadProjection | null,
244
- environmentId: EnvironmentId,
245
-) {
246
- "use memo";
259
const shells: ReadonlyArray<OrchestrationV2ThreadShell> = [
260
...threadShells
249
- .filter((thread) => thread.environmentId === environmentId)
261
+ .filter((thread) => thread.environmentId === props.environmentId)
262
.map((thread) => thread.source),
263
...(archivedShells ?? []),
264
];
253
- return deriveThreadRelationshipGraph({ threads: shells, projection });
254
-}
255
-
256
-export function ThreadRelationshipsPanel(props: {
257
- readonly environmentId: EnvironmentId;
258
- readonly threadId: ThreadId;
259
-}) {
260
- const ref = scopeThreadRef(props.environmentId, props.threadId);
261
- const projection = useThreadProjection(ref)?.projection ?? null;
262
- const providers = useServerConfigs().get(props.environmentId)?.providers;
263
- const { subagentsByThreadId, workflowGroupsById } = useSubagentLookups(projection?.subagents);
264
- const threadShells = useThreadShells();
265
- const projects = useProjects().filter((project) => project.environmentId === props.environmentId);
266
- const archived = useArchivedThreadSnapshots([props.environmentId]);
267
- const archivedShells = archived.snapshots.find(
268
- (entry) => entry.environmentId === props.environmentId,
269
- )?.snapshot.threads;
270
- const graph = useThreadRelationshipGraph(
271
- threadShells,
272
- archivedShells,
273
- projection,
274
- props.environmentId,
275
- );
265
+ const graph = deriveThreadRelationshipGraph({ threads: shells, projection });
266
const currentThread = projection?.thread ?? graph.nodes.get(props.threadId)?.thread;
267
const currentProject = projects.find((project) => project.id === currentThread?.projectId);
278
- const navigate = useNavigate();
279
- const mergeBack = useAtomCommand(threadEnvironment.mergeBack);
280
- const stopSession = useAtomCommand(threadEnvironment.stopSession);
281
- const interruptTurn = useAtomCommand(threadEnvironment.interruptTurn);
282
- const stopWorkflowCommand = useAtomCommand(orchestrationEnvironment.stopWorkflow);
283
- const canOperateWorkflow = useAtomValue(
284
- orchestrationEnvironment.stopWorkflow.permissionAtom(props.environmentId),
285
- );
286
- const [busyAction, setBusyAction] = useState<"merge" | "detach" | null>(null);
287
- const [stoppingId, setStoppingId] = useState<string | null>(null);
268
const latestMergeBackRun = projection === null ? null : resolveLatestMergeBackRun(projection);
269
const mergeTargetThreadId = resolveMergeBackTargetThreadId(projection);
270
const relationshipRows = orderWebThreadLineageRows({