@devries-cameron20 / t3code Mirror · read-only / commits / e6c0c5e8b8
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 23, 05:30 UTC

refactor(web): the queued runs control keeps its caching without "use memo" hooks (#20779)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 16, 2026 at 23:27 UTC e6c0c5e8b8504d9f4921d4d332d1bcc9b1ea4cf3
1 file changed +22 -34
apps/web/src/components/chat/QueuedRunsControl.tsx
+22 -34
@@ -49,27 +49,15 @@ export interface QueuedRunsControlHandle {
49
50 type ThreadQueueProjection = Parameters<typeof deriveThreadQueueWorkflowState>[0];
51
52 -// Separate hooks so these stay cached across the useAssetUrls call, which keys on
53 -// the resources array.
54 -function useQueueWorkflow(projection: ThreadQueueProjection | undefined) {
55 - "use memo";
56 - const workflow = projection ? deriveThreadQueueWorkflowState(projection) : null;
57 - const queuedImageAttachmentIds: string[] = [];
58 - for (const { attachments } of workflow?.queuedRuns ?? []) {
59 - for (const attachment of attachments) {
60 - if (attachment.type === "image") queuedImageAttachmentIds.push(attachment.id);
61 - }
62 - }
63 - const queuedImageAttachmentResources = queuedImageAttachmentIds.map((attachmentId) => ({
64 - _tag: "attachment" as const,
65 - attachmentId,
66 - }));
67 - return { workflow, queuedImageAttachmentIds, queuedImageAttachmentResources };
68 -}
69 -
70 -function useAcknowledgedMessageIds(projection: ThreadQueueProjection | undefined) {
71 - "use memo";
72 - return new Set((projection?.messages ?? []).map((message) => message.id));
52 +function queuedImageResources(projection: ThreadQueueProjection | undefined) {
53 + if (!projection) return [];
54 + return deriveThreadQueueWorkflowState(projection).queuedRuns.flatMap(({ attachments }) =>
55 + attachments.flatMap((attachment) =>
56 + attachment.type === "image"
57 + ? [{ _tag: "attachment" as const, attachmentId: attachment.id }]
58 + : [],
59 + ),
60 + );
61 }
62
63 export function QueuedRunsControl({
@@ -104,25 +92,26 @@ export function QueuedRunsControl({
92 // Drags must start from the grip, not from an accidental text-drag on the
93 // row. The grip arms its run id on pointerdown; dragstart verifies it.
94 const dragArmedRunIdRef = useRef<RunId | null>(null);
107 - const { workflow, queuedImageAttachmentIds, queuedImageAttachmentResources } =
108 - useQueueWorkflow(projection);
109 - const queued = workflow?.queuedRuns ?? [];
110 - const activeRun = workflow?.activeRun ?? null;
111 - const canReorder = workflow?.canReorder === true;
95 + const steerInFlightRef = useRef(false);
96 + // Once the projection holds the message the optimistic copy is stale no
97 + // matter what happened to its run — keying on still-queued runs alone would
98 + // resurrect a phantom "pending" row after the run is cancelled or started.
99 + const acknowledgedMessageIds = new Set((projection?.messages ?? []).map((message) => message.id));
100 + const queuedImageAttachmentResources = queuedImageResources(projection);
101 const queuedImageAttachmentUrls = useAssetUrls(
102 props.environmentId,
103 queuedImageAttachmentResources,
104 );
105 + const workflow = projection ? deriveThreadQueueWorkflowState(projection) : null;
106 + const queued = workflow?.queuedRuns ?? [];
107 + const activeRun = workflow?.activeRun ?? null;
108 + const canReorder = workflow?.canReorder === true;
109 const queuedImageUrlById = new Map(
117 - queuedImageAttachmentIds.flatMap((attachmentId, index) => {
118 - const url = queuedImageAttachmentUrls[index];
119 - return url ? [[attachmentId, url] as const] : [];
110 + queuedImageAttachmentUrls.flatMap((url, index) => {
111 + const resource = queuedImageAttachmentResources[index];
112 + return url && resource ? [[resource.attachmentId, url] as const] : [];
113 }),
114 );
122 - // Once the projection holds the message the optimistic copy is stale no
123 - // matter what happened to its run — keying on still-queued runs alone would
124 - // resurrect a phantom "pending" row after the run is cancelled or started.
125 - const acknowledgedMessageIds = useAcknowledgedMessageIds(projection);
115 const optimisticQueued = props.optimisticMessages.filter(
116 (message) => message.inputIntent === "queued_turn" && !acknowledgedMessageIds.has(message.id),
117 );
@@ -180,7 +169,6 @@ export function QueuedRunsControl({
169 void move(runId, queued[insertIndex]?.run.id ?? null);
170 };
171
183 - const steerInFlightRef = useRef(false);
172 const steer = async (queuedRunId: RunId) => {
173 if (activeRun === null || !workflow?.canPromoteToSteer || steerInFlightRef.current) return;
174 steerInFlightRef.current = true;