@devries-cameron20 / t3code Mirror · read-only / commits / 9fa39677e1
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, 08:00 UTC

perf(web): the queued runs control compiles with the React Compiler (#20475)

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

Julius Marminge committed Oct 16, 2026 at 18:46 UTC 9fa39677e16a339e9ed0e29a1d8e4cec3a500380
2 files changed +51 -60
apps/web/reactCompiledFiles.ts
+1
@@ -50,4 +50,5 @@ export const REACT_COMPILED_FILES = [
50 "apps/web/src/hooks/useLocalStorage.ts",
51 "apps/web/src/hooks/useTheme.ts",
52 "apps/web/src/hooks/useSettings.ts",
53 + "apps/web/src/components/chat/QueuedRunsControl.tsx",
54 ] as const;
apps/web/src/components/chat/QueuedRunsControl.tsx
+50 -60
@@ -15,7 +15,7 @@ import {
15 ListOrderedIcon,
16 PencilIcon,
17 } from "lucide-react";
18 -import { useId, useImperativeHandle, useMemo, useRef, useState, type Ref } from "react";
18 +import { useId, useImperativeHandle, useRef, useState, type Ref } from "react";
19
20 import { useAssetUrls } from "../../assets/assetUrls";
21 import { threadEnvironment } from "../../state/threads";
@@ -47,6 +47,31 @@ export interface QueuedRunsControlHandle {
47 editLatest: (repeat: boolean) => boolean;
48 }
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));
73 +}
74 +
75 export function QueuedRunsControl({
76 ref,
77 ...props
@@ -79,51 +104,25 @@ export function QueuedRunsControl({
104 // Drags must start from the grip, not from an accidental text-drag on the
105 // row. The grip arms its run id on pointerdown; dragstart verifies it.
106 const dragArmedRunIdRef = useRef<RunId | null>(null);
82 - const workflow = useMemo(
83 - () => (projection ? deriveThreadQueueWorkflowState(projection) : null),
84 - [projection],
85 - );
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;
89 - const queuedImageAttachmentIds = useMemo(() => {
90 - const ids: string[] = [];
91 - for (const { attachments } of workflow?.queuedRuns ?? []) {
92 - for (const attachment of attachments) {
93 - if (attachment.type === "image") ids.push(attachment.id);
94 - }
95 - }
96 - return ids;
97 - }, [workflow]);
98 - const queuedImageAttachmentResources = useMemo(
99 - () =>
100 - queuedImageAttachmentIds.map((attachmentId) => ({
101 - _tag: "attachment" as const,
102 - attachmentId,
103 - })),
104 - [queuedImageAttachmentIds],
105 - );
112 const queuedImageAttachmentUrls = useAssetUrls(
113 props.environmentId,
114 queuedImageAttachmentResources,
115 );
110 - const queuedImageUrlById = useMemo(
111 - () =>
112 - new Map(
113 - queuedImageAttachmentIds.flatMap((attachmentId, index) => {
114 - const url = queuedImageAttachmentUrls[index];
115 - return url ? [[attachmentId, url] as const] : [];
116 - }),
117 - ),
118 - [queuedImageAttachmentIds, queuedImageAttachmentUrls],
116 + const queuedImageUrlById = new Map(
117 + queuedImageAttachmentIds.flatMap((attachmentId, index) => {
118 + const url = queuedImageAttachmentUrls[index];
119 + return url ? [[attachmentId, url] as const] : [];
120 + }),
121 );
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.
123 - const acknowledgedMessageIds = useMemo(
124 - () => new Set((projection?.messages ?? []).map((message) => message.id)),
125 - [projection],
126 - );
125 + const acknowledgedMessageIds = useAcknowledgedMessageIds(projection);
126 const optimisticQueued = props.optimisticMessages.filter(
127 (message) => message.inputIntent === "queued_turn" && !acknowledgedMessageIds.has(message.id),
128 );
@@ -164,14 +163,11 @@ export function QueuedRunsControl({
163
164 const move = async (runId: RunId, beforeRunId: RunId | null) => {
165 setBusyRunId(runId);
167 - try {
168 - await reorder({
169 - environmentId: props.environmentId,
170 - input: { threadId: props.threadId, runId, beforeRunId },
171 - });
172 - } finally {
173 - setBusyRunId(null);
174 - }
166 + await reorder({
167 + environmentId: props.environmentId,
168 + input: { threadId: props.threadId, runId, beforeRunId },
169 + });
170 + setBusyRunId(null);
171 };
172
173 const completeDrag = (runId: RunId, insertIndex: number | null) => {
@@ -189,15 +185,12 @@ export function QueuedRunsControl({
185 if (activeRun === null || !workflow?.canPromoteToSteer || steerInFlightRef.current) return;
186 steerInFlightRef.current = true;
187 setBusyRunId(queuedRunId);
192 - try {
193 - await promote({
194 - environmentId: props.environmentId,
195 - input: { threadId: props.threadId, queuedRunId, targetRunId: activeRun.id },
196 - });
197 - } finally {
198 - steerInFlightRef.current = false;
199 - setBusyRunId(null);
200 - }
188 + await promote({
189 + environmentId: props.environmentId,
190 + input: { threadId: props.threadId, queuedRunId, targetRunId: activeRun.id },
191 + });
192 + steerInFlightRef.current = false;
193 + setBusyRunId(null);
194 };
195
196 useImperativeHandle(ref, () => ({
@@ -229,14 +222,11 @@ export function QueuedRunsControl({
222
223 const remove = async (runId: RunId) => {
224 setBusyRunId(runId);
232 - try {
233 - await cancel({
234 - environmentId: props.environmentId,
235 - input: { threadId: props.threadId, runId },
236 - });
237 - } finally {
238 - setBusyRunId(null);
239 - }
225 + await cancel({
226 + environmentId: props.environmentId,
227 + input: { threadId: props.threadId, runId },
228 + });
229 + setBusyRunId(null);
230 };
231
232 return (