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
refactor(web): let the React Compiler compile usePendingThreadRequests (#20294)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 16, 2026 at 17:39 UTC
f7916ad07cc1461fd15e41a70ae045188ae0b6ca
2 files changed
+61
-97
apps/web/src/components/chat/usePendingThreadRequests.ts
+60
-97
@@ -16,7 +16,7 @@ import {
16
isAtomCommandInterrupted,
17
squashAtomCommandFailure,
18
} from "@t3tools/client-runtime/state/runtime";
19
-import { useEffect, useMemo, useRef, useState, type RefObject, type SetStateAction } from "react";
19
+import { useEffect, useRef, useState, type RefObject, type SetStateAction } from "react";
20
import { useShallow } from "zustand/react/shallow";
21
import { DraftId, useComposerDraftStore } from "../../composerDraftStore";
22
import { useStableCallback } from "../../hooks/useStableCallback";
@@ -53,7 +53,7 @@ const EMPTY_PENDING_USER_INPUT_ANSWERS: Record<string, PendingUserInputDraftAnsw
53
function makePendingCustomAnswerSetter(input: {
54
readonly activePendingUserInput: PendingUserInput | null;
55
readonly activePendingRequestKey: string;
56
- readonly promptRef: { current: string };
56
+ readonly writePrompt: (prompt: string) => void;
57
readonly setPendingUserInputAnswersByRequestId: (
58
update: SetStateAction<Record<string, Record<string, PendingUserInputDraftAnswer>>>,
59
) => void;
@@ -67,7 +67,7 @@ function makePendingCustomAnswerSetter(input: {
67
if (!question || question.allowCustomAnswer === false) {
68
return;
69
}
70
- input.promptRef.current = value;
70
+ input.writePrompt(value);
71
input.setPendingUserInputAnswersByRequestId((existing) => ({
72
...existing,
73
[activePendingRequestKey]: {
@@ -132,21 +132,12 @@ export function usePendingThreadRequests(input: {
132
>({});
133
const [pendingUserInputQuestionIndexByRequestId, setPendingUserInputQuestionIndexByRequestId] =
134
useState<Record<string, number>>({});
135
- const pendingRequests = useMemo(
136
- () =>
137
- serverProjection === null
138
- ? { approvals: [], userInputs: [] }
139
- : derivePendingThreadRequests(serverProjection),
140
- [serverProjection],
141
- );
142
- const pendingApprovals = useMemo(
143
- () => derivePendingApprovals(pendingRequests.approvals),
144
- [pendingRequests.approvals],
145
- );
146
- const pendingUserInputs = useMemo(
147
- () => derivePendingUserInputs(pendingRequests.userInputs),
148
- [pendingRequests.userInputs],
149
- );
135
+ const pendingRequests =
136
+ serverProjection === null
137
+ ? { approvals: [], userInputs: [] }
138
+ : derivePendingThreadRequests(serverProjection);
139
+ const pendingApprovals = derivePendingApprovals(pendingRequests.approvals);
140
+ const pendingUserInputs = derivePendingUserInputs(pendingRequests.userInputs);
141
const activePendingUserInput = pendingUserInputs[0] ?? null;
142
const activePendingRequestKey = JSON.stringify([
143
environmentId,
@@ -166,22 +157,13 @@ export function usePendingThreadRequests(input: {
157
return seeded === drafts ? existing : { ...existing, [activePendingRequestKey]: seeded };
158
});
159
}
169
- const pendingQuestionDraftKeys = useMemo(
170
- () =>
171
- activeThreadId
172
- ? pendingUserInputs.flatMap((request) =>
173
- request.questions.map((question) =>
174
- questionAttachmentDraftId(
175
- environmentId,
176
- activeThreadId,
177
- request.requestId,
178
- question.id,
179
- ),
180
- ),
181
- )
182
- : [],
183
- [activeThreadId, environmentId, pendingUserInputs],
184
- );
160
+ const pendingQuestionDraftKeys = activeThreadId
161
+ ? pendingUserInputs.flatMap((request) =>
162
+ request.questions.map((question) =>
163
+ questionAttachmentDraftId(environmentId, activeThreadId, request.requestId, question.id),
164
+ ),
165
+ )
166
+ : [];
167
const questionComposerDrafts = useComposerDraftStore(
168
useShallow((state) =>
169
Object.fromEntries(
@@ -237,63 +219,45 @@ export function usePendingThreadRequests(input: {
219
clearQuestionAttachmentDraft(DraftId.make(key));
220
}
221
}, [environmentId, activeThread, pendingUserInputs]);
240
- const activePendingDraftAnswers = useMemo(() => {
241
- if (!activePendingUserInput || !activeThreadId) return EMPTY_PENDING_USER_INPUT_ANSWERS;
242
- return Object.fromEntries(
243
- activePendingUserInput.questions.map((question) => {
244
- const key = questionAttachmentDraftId(
245
- environmentId,
246
- activeThreadId,
247
- activePendingUserInput.requestId,
248
- question.id,
222
+ const activePendingDraftAnswers =
223
+ !activePendingUserInput || !activeThreadId
224
+ ? EMPTY_PENDING_USER_INPUT_ANSWERS
225
+ : Object.fromEntries(
226
+ activePendingUserInput.questions.map((question) => {
227
+ const key = questionAttachmentDraftId(
228
+ environmentId,
229
+ activeThreadId,
230
+ activePendingUserInput.requestId,
231
+ question.id,
232
+ );
233
+ const draft = questionComposerDrafts[key];
234
+ const attachments = draft ? [...draft.images, ...draft.files] : [];
235
+ return [
236
+ question.id,
237
+ {
238
+ ...pendingUserInputAnswersByRequestId[activePendingRequestKey]?.[question.id],
239
+ attachmentCount: attachments.length,
240
+ attachmentsBlocked:
241
+ (attachments.length > 0 && !supportsQuestionAttachments) ||
242
+ (questionPreparations[key] ?? 0) > 0 ||
243
+ questionUploadsBlocked[key] === true,
244
+ },
245
+ ];
246
+ }),
247
);
250
- const draft = questionComposerDrafts[key];
251
- const attachments = draft ? [...draft.images, ...draft.files] : [];
252
- return [
253
- question.id,
254
- {
255
- ...pendingUserInputAnswersByRequestId[activePendingRequestKey]?.[question.id],
256
- attachmentCount: attachments.length,
257
- attachmentsBlocked:
258
- (attachments.length > 0 && !supportsQuestionAttachments) ||
259
- (questionPreparations[key] ?? 0) > 0 ||
260
- questionUploadsBlocked[key] === true,
261
- },
262
- ];
263
- }),
264
- );
265
- }, [
266
- activePendingUserInput,
267
- activeThreadId,
268
- environmentId,
269
- questionComposerDrafts,
270
- questionUploadsBlocked,
271
- supportsQuestionAttachments,
272
- questionPreparations,
273
- pendingUserInputAnswersByRequestId,
274
- activePendingRequestKey,
275
- ]);
248
const activePendingQuestionIndex = activePendingUserInput
249
? (pendingUserInputQuestionIndexByRequestId[activePendingRequestKey] ?? 0)
250
: 0;
279
- const activePendingProgress = useMemo(
280
- () =>
281
- activePendingUserInput
282
- ? derivePendingUserInputProgress(
283
- activePendingUserInput.questions,
284
- activePendingDraftAnswers,
285
- activePendingQuestionIndex,
286
- )
287
- : null,
288
- [activePendingDraftAnswers, activePendingQuestionIndex, activePendingUserInput],
289
- );
290
- const activePendingResolvedAnswers = useMemo(
291
- () =>
292
- activePendingUserInput
293
- ? buildPendingUserInputAnswers(activePendingUserInput.questions, activePendingDraftAnswers)
294
- : null,
295
- [activePendingDraftAnswers, activePendingUserInput],
296
- );
251
+ const activePendingProgress = activePendingUserInput
252
+ ? derivePendingUserInputProgress(
253
+ activePendingUserInput.questions,
254
+ activePendingDraftAnswers,
255
+ activePendingQuestionIndex,
256
+ )
257
+ : null;
258
+ const activePendingResolvedAnswers = activePendingUserInput
259
+ ? buildPendingUserInputAnswers(activePendingUserInput.questions, activePendingDraftAnswers)
260
+ : null;
261
const activePendingIsResponding = activePendingUserInput
262
? activePendingUserInput.responseCapability === "not_resumable" ||
263
respondingUserInputRequestIds.includes(activePendingUserInput.requestId)
@@ -490,16 +454,15 @@ export function usePendingThreadRequests(input: {
454
onSelectActivePendingUserInputOption,
455
);
456
493
- const onChangeActivePendingUserInputCustomAnswer = useMemo(
494
- () =>
495
- makePendingCustomAnswerSetter({
496
- activePendingUserInput,
497
- activePendingRequestKey,
498
- promptRef,
499
- setPendingUserInputAnswersByRequestId,
500
- }),
501
- [activePendingUserInput, activePendingRequestKey, promptRef],
502
- );
457
+ const writePrompt = useStableCallback((prompt: string) => {
458
+ promptRef.current = prompt;
459
+ });
460
+ const onChangeActivePendingUserInputCustomAnswer = makePendingCustomAnswerSetter({
461
+ activePendingUserInput,
462
+ activePendingRequestKey,
463
+ writePrompt,
464
+ setPendingUserInputAnswersByRequestId,
465
+ });
466
467
const onAdvanceActivePendingUserInput = () => {
468
if (
vite.config.ts
+1
@@ -327,6 +327,7 @@ export default defineConfig({
327
// Add a file once it compiles cleanly. ChatView is being split toward this list.
328
files: [
329
"apps/web/src/components/PersistentThreadTerminals.tsx",
330
+ "apps/web/src/components/chat/usePendingThreadRequests.ts",
331
"apps/web/src/components/terminal/**",
332
],
333
rules: {