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 21, 11:00 UTC
perf(web): answering a question no longer re-renders the whole chat view (#32324)
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Omar Espinosa committed
Nov 14, 2026 at 23:47 UTC
4117bd42ec3cb9c08196f0a616e4658ba18af20b
8 files changed
+301
-139
apps/web/src/components/ChatView.tsx
+2
-10
@@ -1385,10 +1385,6 @@ export default function ChatView(props: ChatViewProps) {
1385
pendingUserInputs,
1386
activePendingApproval,
1387
activePendingUserInput,
1388
- activePendingDraftAnswers,
1389
- activePendingQuestionIndex,
1390
- activePendingProgress,
1391
- activePendingResolvedAnswers,
1388
activePendingIsResponding,
1389
respondingRequestIds,
1390
onRespondToApproval: onRespondToApprovalStable,
@@ -2976,7 +2972,7 @@ export default function ChatView(props: ChatViewProps) {
2972
readPendingEnvironmentChange,
2973
pendingApprovals,
2974
respondingRequestIds,
2979
- activePendingProgress,
2975
+ activePendingUserInput,
2976
onAdvanceActivePendingUserInput,
2977
onRespondToApproval: onRespondToApprovalStable,
2978
beginLocalDispatch,
@@ -3095,7 +3091,7 @@ export default function ChatView(props: ChatViewProps) {
3091
clientSettingsHydrated &&
3092
!needsLoadBalancing &&
3093
!activeEnvironmentUnavailable &&
3098
- !activePendingProgress &&
3094
+ !activePendingUserInput &&
3095
!feedbackUploading;
3096
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- switches the draft to local mode, then resends the waiting message once sending is idle
3097
useEffect(() => {
@@ -3706,11 +3702,7 @@ export default function ChatView(props: ChatViewProps) {
3702
pendingApprovals={pendingApprovals}
3703
onHeldRequestIdsChange={onHeldRequestIdsChange}
3704
pendingUserInputs={pendingUserInputs}
3709
- activePendingProgress={activePendingProgress}
3710
- activePendingResolvedAnswers={activePendingResolvedAnswers}
3705
activePendingIsResponding={activePendingIsResponding}
3712
- activePendingDraftAnswers={activePendingDraftAnswers}
3713
- activePendingQuestionIndex={activePendingQuestionIndex}
3706
respondingRequestIds={respondingRequestIds}
3707
runtimeMode={runtimeMode}
3708
defaultRuntimeMode={defaultRuntimeMode}
apps/web/src/components/chat/ChatComposer.tsx
+12
-21
@@ -250,7 +250,7 @@ import { type AppModelOption, getAppModelOptionsForInstance } from "../../modelS
250
import type { UnifiedSettings } from "@t3tools/contracts/settings";
251
import { isVideoAttachment, type SessionPhase, type Thread } from "../../types";
252
import { type ComposerPromptHistoryPosition } from "./composerPromptHistory";
253
-import type { PendingUserInputDraftAnswer } from "@t3tools/client-runtime/state/pending-user-input";
253
+import { usePendingUserInputDraft } from "./usePendingThreadRequests";
254
import type { PendingApproval, PendingUserInput, TimelineEntry } from "../../session-logic";
255
import {
256
resolveComposerDispatchMode,
@@ -399,23 +399,7 @@ export interface ChatComposerProps {
399
pendingApprovals: PendingApproval[];
400
onHeldRequestIdsChange: (requestIds: ReadonlySet<string>) => void;
401
pendingUserInputs: PendingUserInput[];
402
- activePendingProgress: {
403
- questionIndex: number;
404
- isLastQuestion: boolean;
405
- canAdvance: boolean;
406
- customAnswer: string;
407
- activeQuestion: {
408
- id: string;
409
- options: ReadonlyArray<unknown>;
410
- initialAnswer?: string | undefined;
411
- multiSelect?: boolean | undefined;
412
- allowCustomAnswer?: boolean | undefined;
413
- } | null;
414
- } | null;
415
- activePendingResolvedAnswers: Record<string, unknown> | null;
402
activePendingIsResponding: boolean;
417
- activePendingDraftAnswers: Record<string, PendingUserInputDraftAnswer>;
418
- activePendingQuestionIndex: number;
403
respondingRequestIds: RuntimeRequestId[];
404
405
runtimeMode: RuntimeMode;
@@ -533,11 +517,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
517
pendingApprovals,
518
onHeldRequestIdsChange,
519
pendingUserInputs: incomingPendingUserInputs,
536
- activePendingProgress: incomingPendingProgress,
537
- activePendingResolvedAnswers,
520
activePendingIsResponding: incomingPendingIsResponding,
539
- activePendingDraftAnswers,
540
- activePendingQuestionIndex,
521
respondingRequestIds,
522
runtimeMode,
523
lockedProvider,
@@ -588,6 +568,17 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
568
editingQueuedAttachments,
569
onRemoveEditingQueuedAttachment,
570
} = props;
571
+ const {
572
+ activePendingProgress: incomingPendingProgress,
573
+ activePendingResolvedAnswers,
574
+ activePendingDraftAnswers,
575
+ activePendingQuestionIndex,
576
+ } = usePendingUserInputDraft({
577
+ environmentId,
578
+ activeThreadId,
579
+ activePendingUserInput: incomingPendingUserInputs[0] ?? null,
580
+ supportsQuestionAttachments,
581
+ });
582
const primaryEnvironmentId = usePrimaryEnvironmentId();
583
const composerDraftTargetKey = composerTargetKey(composerDraftTarget);
584
const {
apps/web/src/components/chat/ComposerPendingUserInputPanel.navigation.browser.test.tsx
+10
-3
@@ -20,7 +20,7 @@ import { act, fakeTimers, render } from "../../../test/render";
20
import { DraftId, useComposerDraftStore } from "../../composerDraftStore";
21
import { makeThreadProjectionFixture } from "../../test-fixtures";
22
import { toastManager } from "../ui/toast";
23
-import { usePendingThreadRequests } from "./usePendingThreadRequests";
23
+import { usePendingThreadRequests, usePendingUserInputDraft } from "./usePendingThreadRequests";
24
25
const threadRef = { environmentId: EnvironmentId.make("env"), threadId: ThreadId.make("thread") };
26
@@ -86,7 +86,7 @@ interface ProbeProps {
86
function useProbeRequests({ environmentId, projection, loading = false, draftTarget }: ProbeProps) {
87
const promptRef = useRef("");
88
const composerRef = useRef(null);
89
- return usePendingThreadRequests({
89
+ const requests = usePendingThreadRequests({
90
environmentId,
91
activeThreadId: projection.thread.id,
92
serverProjection: loading ? null : projection,
@@ -98,9 +98,16 @@ function useProbeRequests({ environmentId, projection, loading = false, draftTar
98
composerRef,
99
setThreadError: () => {},
100
});
101
+ const draft = usePendingUserInputDraft({
102
+ environmentId,
103
+ activeThreadId: projection.thread.id,
104
+ activePendingUserInput: requests.activePendingUserInput,
105
+ supportsQuestionAttachments: false,
106
+ });
107
+ return { ...requests, ...draft };
108
}
109
103
-let requests: ReturnType<typeof usePendingThreadRequests>;
110
+let requests: ReturnType<typeof useProbeRequests>;
111
112
function PendingRequestsProbe(props: ProbeProps) {
113
const state = useProbeRequests(props);
apps/web/src/components/chat/useComposerAttachmentIntake.ts
+2
-1
@@ -18,6 +18,7 @@ import {
18
composerFileNeedsReattach,
19
} from "../../composerDraftStore";
20
import { type ComposerPromptEditorHandle } from "../ComposerPromptEditorTiptap";
21
+import type { PendingUserInputProgress } from "../../pendingUserInput";
22
import type { ComposerAttachmentInsertion } from "../composerAttachmentInsertion";
23
import { type PendingUserInput } from "../../session-logic";
24
import {
@@ -62,7 +63,7 @@ import {
63
*/
64
export function useComposerAttachmentIntake(input: {
65
readonly activeThreadId: ChatComposerProps["activeThreadId"];
65
- readonly activePendingProgress: ChatComposerProps["activePendingProgress"];
66
+ readonly activePendingProgress: PendingUserInputProgress | null;
67
readonly activePendingIsResponding: boolean;
68
readonly pendingUserInputs: ReadonlyArray<PendingUserInput>;
69
readonly supportsQuestionAttachments: boolean;
apps/web/src/components/chat/useComposerSend.ts
+3
-3
@@ -220,7 +220,7 @@ interface ComposerSendInput {
220
readonly readPendingEnvironmentChange: DraftEnvironmentRouting["readPendingEnvironmentChange"];
221
readonly pendingApprovals: PendingThreadRequests["pendingApprovals"];
222
readonly respondingRequestIds: PendingThreadRequests["respondingRequestIds"];
223
- readonly activePendingProgress: PendingThreadRequests["activePendingProgress"];
223
+ readonly activePendingUserInput: PendingThreadRequests["activePendingUserInput"];
224
readonly onAdvanceActivePendingUserInput: PendingThreadRequests["onAdvanceActivePendingUserInput"];
225
readonly onRespondToApproval: PendingThreadRequests["onRespondToApproval"];
226
readonly beginLocalDispatch: LocalDispatchState["beginLocalDispatch"];
@@ -316,7 +316,7 @@ export function useComposerSend(input: ComposerSendInput) {
316
readPendingEnvironmentChange,
317
pendingApprovals,
318
respondingRequestIds,
319
- activePendingProgress,
319
+ activePendingUserInput,
320
onAdvanceActivePendingUserInput,
321
onRespondToApproval: onRespondToApprovalStable,
322
beginLocalDispatch,
@@ -410,7 +410,7 @@ export function useComposerSend(input: ComposerSendInput) {
410
? parseSideChatCommand(promptAtSend)
411
: null;
412
const answeringQuestion =
413
- Boolean(activePendingProgress) && sendCtx?.answeringPendingUserInput !== false;
413
+ Boolean(activePendingUserInput) && sendCtx?.answeringPendingUserInput !== false;
414
const startsSideChat =
415
onSideChat !== undefined && sideChatCommand !== null && sideChatDisabledReason === null;
416
// An answer responds to the open request rather than starting a turn, so the new-message
apps/web/src/components/chat/useComposerStash.ts
+2
-1
@@ -25,6 +25,7 @@ import {
25
partitionStashAttachments,
26
usePromptStashStore,
27
} from "../../promptStashStore";
28
+import type { PendingUserInputProgress } from "../../pendingUserInput";
29
import { type PendingUserInput } from "../../session-logic";
30
import { type ReviewCommentContext } from "../../reviewCommentContext";
31
import { collapseExpandedComposerCursor } from "../../composer-logic";
@@ -80,7 +81,7 @@ export function useComposerStash(input: {
81
readonly routeThreadRef: ChatComposerProps["routeThreadRef"];
82
readonly projectSelectionRequired: boolean;
83
readonly pendingUserInputs: ReadonlyArray<PendingUserInput>;
83
- readonly activePendingProgress: ChatComposerProps["activePendingProgress"];
84
+ readonly activePendingProgress: PendingUserInputProgress | null;
85
readonly prompt: string;
86
readonly composerMenuOpen: boolean;
87
readonly isComposerCollapsedMobile: boolean;
apps/web/src/components/chat/usePendingThreadRequests.ts
+184
-98
@@ -19,7 +19,11 @@ import {
19
} from "@t3tools/client-runtime/state/runtime";
20
import { useRef, useState, type RefObject, type SetStateAction } from "react";
21
import { useShallow } from "zustand/react/shallow";
22
-import { type DraftId, useComposerDraftStore } from "../../composerDraftStore";
22
+import {
23
+ type ComposerThreadDraftState,
24
+ type DraftId,
25
+ useComposerDraftStore,
26
+} from "../../composerDraftStore";
27
import { useStableCallback } from "../../hooks/useStableCallback";
28
import { getUploadedAttachments, useAttachmentUploadStore } from "../../lib/attachmentUploadQueue";
29
import {
@@ -60,6 +64,171 @@ const NO_PENDING_REQUESTS = { approvals: [], userInputs: [] } as const;
64
const NO_PENDING_APPROVALS: ReturnType<typeof derivePendingApprovals> = [];
65
const NO_PENDING_USER_INPUTS: ReturnType<typeof derivePendingUserInputs> = [];
66
67
+interface PendingUserInputDraftScope {
68
+ readonly environmentId: EnvironmentId;
69
+ readonly activeThreadId: ThreadId | null;
70
+ readonly activePendingUserInput: PendingUserInput | null;
71
+ readonly supportsQuestionAttachments: boolean;
72
+}
73
+
74
+function pendingUserInputDraftKeys(scope: PendingUserInputDraftScope) {
75
+ const { environmentId, activeThreadId, activePendingUserInput } = scope;
76
+ return {
77
+ requestKey: userInputDraftKey(environmentId, activeThreadId, activePendingUserInput?.requestId),
78
+ questionKeys:
79
+ activeThreadId && activePendingUserInput
80
+ ? activePendingUserInput.questions.map((question) =>
81
+ questionAttachmentDraftId(
82
+ environmentId,
83
+ activeThreadId,
84
+ activePendingUserInput.requestId,
85
+ question.id,
86
+ ),
87
+ )
88
+ : [],
89
+ };
90
+}
91
+
92
+const selectQuestionComposerDrafts =
93
+ (keys: ReadonlyArray<string>) =>
94
+ (state: { readonly draftsByThreadKey: Record<string, ComposerThreadDraftState> }) =>
95
+ Object.fromEntries(keys.map((key) => [key, state.draftsByThreadKey[key]]));
96
+
97
+const selectQuestionUploadsBlocked =
98
+ (
99
+ keys: ReadonlyArray<string>,
100
+ questionComposerDrafts: Record<string, ComposerThreadDraftState | undefined>,
101
+ environmentId: EnvironmentId,
102
+ ) =>
103
+ (state: ReturnType<typeof useAttachmentUploadStore.getState>) =>
104
+ Object.fromEntries(
105
+ keys.map((key) => {
106
+ const draft = questionComposerDrafts[key];
107
+ const attachments = draft ? [...draft.images, ...draft.files] : [];
108
+ return [
109
+ key,
110
+ attachments.some((attachment) => {
111
+ const upload = state.uploadsByImageId[attachment.id];
112
+ return upload?.status !== "ready" || upload.environmentId !== environmentId;
113
+ }),
114
+ ];
115
+ }),
116
+ );
117
+
118
+const selectQuestionPreparations =
119
+ (keys: ReadonlyArray<string>) => (state: { readonly counts: Record<string, number> }) =>
120
+ Object.fromEntries(keys.map((key) => [key, state.counts[key] ?? 0]));
121
+
122
+function deriveActivePendingDraft(
123
+ scope: PendingUserInputDraftScope,
124
+ storedPendingAnswerDrafts: Record<string, PendingUserInputDraftAnswer>,
125
+ activePendingQuestionIndex: number,
126
+ questionComposerDrafts: Record<string, ComposerThreadDraftState | undefined>,
127
+ questionUploadsBlocked: Record<string, boolean>,
128
+ questionPreparations: Record<string, number>,
129
+) {
130
+ const { environmentId, activeThreadId, activePendingUserInput, supportsQuestionAttachments } =
131
+ scope;
132
+ // Suggested answers are shown until the user edits them; only edits are stored.
133
+ const activePendingAnswerDrafts: Record<string, PendingUserInputDraftAnswer> =
134
+ activePendingUserInput
135
+ ? seedUserInputDraftAnswers(activePendingUserInput.questions, storedPendingAnswerDrafts)
136
+ : storedPendingAnswerDrafts;
137
+ const activePendingDraftAnswers =
138
+ !activePendingUserInput || !activeThreadId
139
+ ? EMPTY_PENDING_USER_INPUT_ANSWERS
140
+ : Object.fromEntries(
141
+ activePendingUserInput.questions.map((question) => {
142
+ const key = questionAttachmentDraftId(
143
+ environmentId,
144
+ activeThreadId,
145
+ activePendingUserInput.requestId,
146
+ question.id,
147
+ );
148
+ const draft = questionComposerDrafts[key];
149
+ const attachments = draft ? [...draft.images, ...draft.files] : [];
150
+ return [
151
+ question.id,
152
+ {
153
+ ...activePendingAnswerDrafts[question.id],
154
+ attachmentCount: attachments.length,
155
+ attachmentsBlocked:
156
+ (attachments.length > 0 && !supportsQuestionAttachments) ||
157
+ (questionPreparations[key] ?? 0) > 0 ||
158
+ questionUploadsBlocked[key] === true,
159
+ },
160
+ ];
161
+ }),
162
+ );
163
+ const activePendingProgress = activePendingUserInput
164
+ ? derivePendingUserInputProgress(
165
+ activePendingUserInput.questions,
166
+ activePendingDraftAnswers,
167
+ activePendingQuestionIndex,
168
+ )
169
+ : null;
170
+ const activePendingResolvedAnswers = activePendingUserInput
171
+ ? buildPendingUserInputAnswers(activePendingUserInput.questions, activePendingDraftAnswers)
172
+ : null;
173
+ return {
174
+ activePendingDraftAnswers,
175
+ activePendingQuestionIndex,
176
+ activePendingProgress,
177
+ activePendingResolvedAnswers,
178
+ };
179
+}
180
+
181
+/**
182
+ * The open question's answers, position and progress. These change on every keystroke, so
183
+ * the composer subscribes to them rather than the chat view.
184
+ */
185
+export function usePendingUserInputDraft(scope: PendingUserInputDraftScope) {
186
+ const { requestKey, questionKeys: keys } = pendingUserInputDraftKeys(scope);
187
+ const storedPendingAnswerDrafts = usePendingUserInputAnswers(
188
+ (state) => state[requestKey] ?? EMPTY_PENDING_USER_INPUT_ANSWERS,
189
+ );
190
+ const activePendingQuestionIndex = usePendingUserInputQuestionIndex(
191
+ (state) => state[requestKey] ?? 0,
192
+ );
193
+ const questionComposerDrafts = useComposerDraftStore(
194
+ useShallow(selectQuestionComposerDrafts(keys)),
195
+ );
196
+ const questionUploadsBlocked = useAttachmentUploadStore(
197
+ useShallow(selectQuestionUploadsBlocked(keys, questionComposerDrafts, scope.environmentId)),
198
+ );
199
+ const questionPreparations = useQuestionAttachmentPreparation(
200
+ useShallow(selectQuestionPreparations(keys)),
201
+ );
202
+ return deriveActivePendingDraft(
203
+ scope,
204
+ storedPendingAnswerDrafts,
205
+ activePendingQuestionIndex,
206
+ questionComposerDrafts,
207
+ questionUploadsBlocked,
208
+ questionPreparations,
209
+ );
210
+}
211
+
212
+// Request callbacks read drafts when called, so the chat view never subscribes to them.
213
+function readPendingUserInputDraft(scope: PendingUserInputDraftScope) {
214
+ const { requestKey, questionKeys: keys } = pendingUserInputDraftKeys(scope);
215
+ const questionComposerDrafts = selectQuestionComposerDrafts(keys)(
216
+ useComposerDraftStore.getState(),
217
+ );
218
+ return deriveActivePendingDraft(
219
+ scope,
220
+ usePendingUserInputAnswers.getState()[requestKey] ?? EMPTY_PENDING_USER_INPUT_ANSWERS,
221
+ usePendingUserInputQuestionIndex.getState()[requestKey] ?? 0,
222
+ questionComposerDrafts,
223
+ selectQuestionUploadsBlocked(
224
+ keys,
225
+ questionComposerDrafts,
226
+ scope.environmentId,
227
+ )(useAttachmentUploadStore.getState()),
228
+ selectQuestionPreparations(keys)(useQuestionAttachmentPreparation.getState()),
229
+ );
230
+}
231
+
232
function makePendingCustomAnswerSetter(input: {
233
readonly activePendingUserInput: PendingUserInput | null;
234
readonly activePendingRequestKey: string;
@@ -162,89 +331,12 @@ export function usePendingThreadRequests(input: {
331
activeThreadId,
332
activePendingUserInput?.requestId,
333
);
165
- const storedPendingAnswerDrafts = usePendingUserInputAnswers(
166
- (state) => state[activePendingRequestKey] ?? EMPTY_PENDING_USER_INPUT_ANSWERS,
167
- );
168
- // Suggested answers are shown until the user edits them; only edits are stored.
169
- const activePendingAnswerDrafts: Record<string, PendingUserInputDraftAnswer> =
170
- activePendingUserInput
171
- ? seedUserInputDraftAnswers(activePendingUserInput.questions, storedPendingAnswerDrafts)
172
- : storedPendingAnswerDrafts;
173
- const activePendingQuestionIndex = usePendingUserInputQuestionIndex(
174
- (state) => state[activePendingRequestKey] ?? 0,
175
- );
176
- const pendingQuestionDraftKeys = activeThreadId
177
- ? pendingUserInputs.flatMap((request) =>
178
- request.questions.map((question) =>
179
- questionAttachmentDraftId(environmentId, activeThreadId, request.requestId, question.id),
180
- ),
181
- )
182
- : [];
183
- const questionComposerDrafts = useComposerDraftStore(
184
- useShallow((state) =>
185
- Object.fromEntries(
186
- pendingQuestionDraftKeys.map((key) => [key, state.draftsByThreadKey[key]]),
187
- ),
188
- ),
189
- );
190
- const questionUploadsBlocked = useAttachmentUploadStore(
191
- useShallow((state) =>
192
- Object.fromEntries(
193
- pendingQuestionDraftKeys.map((key) => {
194
- const draft = questionComposerDrafts[key];
195
- const attachments = draft ? [...draft.images, ...draft.files] : [];
196
- return [
197
- key,
198
- attachments.some((attachment) => {
199
- const upload = state.uploadsByImageId[attachment.id];
200
- return upload?.status !== "ready" || upload.environmentId !== environmentId;
201
- }),
202
- ];
203
- }),
204
- ),
205
- ),
206
- );
207
- const questionPreparations = useQuestionAttachmentPreparation(
208
- useShallow((state) =>
209
- Object.fromEntries(pendingQuestionDraftKeys.map((key) => [key, state.counts[key] ?? 0])),
210
- ),
211
- );
212
- const activePendingDraftAnswers =
213
- !activePendingUserInput || !activeThreadId
214
- ? EMPTY_PENDING_USER_INPUT_ANSWERS
215
- : Object.fromEntries(
216
- activePendingUserInput.questions.map((question) => {
217
- const key = questionAttachmentDraftId(
218
- environmentId,
219
- activeThreadId,
220
- activePendingUserInput.requestId,
221
- question.id,
222
- );
223
- const draft = questionComposerDrafts[key];
224
- const attachments = draft ? [...draft.images, ...draft.files] : [];
225
- return [
226
- question.id,
227
- {
228
- ...activePendingAnswerDrafts[question.id],
229
- attachmentCount: attachments.length,
230
- attachmentsBlocked:
231
- (attachments.length > 0 && !supportsQuestionAttachments) ||
232
- (questionPreparations[key] ?? 0) > 0 ||
233
- questionUploadsBlocked[key] === true,
234
- },
235
- ];
236
- }),
237
- );
238
- const activePendingProgress = activePendingUserInput
239
- ? derivePendingUserInputProgress(
240
- activePendingUserInput.questions,
241
- activePendingDraftAnswers,
242
- activePendingQuestionIndex,
243
- )
244
- : null;
245
- const activePendingResolvedAnswers = activePendingUserInput
246
- ? buildPendingUserInputAnswers(activePendingUserInput.questions, activePendingDraftAnswers)
247
- : null;
334
+ const draftScope = {
335
+ environmentId,
336
+ activeThreadId,
337
+ activePendingUserInput,
338
+ supportsQuestionAttachments,
339
+ };
340
const activePendingIsResponding = activePendingUserInput
341
? activePendingUserInput.responseCapability === "not_resumable" ||
342
respondingUserInputRequestIds.includes(activePendingUserInput.requestId)
@@ -392,7 +484,8 @@ export function usePendingThreadRequests(input: {
484
}
485
// The option replaces the custom answer. Anything typed there is the
486
// user's text, so it goes back to the thread draft instead of vanishing.
395
- const displacedAnswer = activePendingAnswerDrafts[questionId]?.customAnswer;
487
+ const displacedAnswer =
488
+ readPendingUserInputDraft(draftScope).activePendingDraftAnswers[questionId]?.customAnswer;
489
const currentPrompt =
490
useComposerDraftStore.getState().getComposerDraft(composerDraftTarget)?.prompt ?? "";
491
const nextPrompt = carryDisplacedCustomAnswerIntoPrompt(currentPrompt, displacedAnswer);
@@ -428,10 +521,7 @@ export function usePendingThreadRequests(input: {
521
}
522
}
523
setPendingUserInputAnswersByRequestId((existing) => {
431
- const question =
432
- (activePendingProgress?.activeQuestion?.id === questionId
433
- ? activePendingProgress.activeQuestion
434
- : undefined) ?? activePendingUserInput.questions.find((entry) => entry.id === questionId);
524
+ const question = activePendingUserInput.questions.find((entry) => entry.id === questionId);
525
if (!question) {
526
return existing;
527
}
@@ -493,13 +583,12 @@ export function usePendingThreadRequests(input: {
583
});
584
585
const onAdvanceActivePendingUserInput = () => {
496
- if (
497
- !activePendingUserInput ||
498
- activePendingUserInput.responseCapability === "not_resumable" ||
499
- !activePendingProgress
500
- ) {
586
+ if (!activePendingUserInput || activePendingUserInput.responseCapability === "not_resumable") {
587
return;
588
}
589
+ const { activePendingProgress, activePendingResolvedAnswers } =
590
+ readPendingUserInputDraft(draftScope);
591
+ if (!activePendingProgress) return;
592
if (activePendingProgress.isLastQuestion) {
593
if (activePendingResolvedAnswers) {
594
void onRespondToUserInput(activePendingUserInput.requestId, activePendingResolvedAnswers);
@@ -512,6 +601,7 @@ export function usePendingThreadRequests(input: {
601
const onAdvanceActivePendingUserInputStable = useStableCallback(onAdvanceActivePendingUserInput);
602
603
const onPreviousActivePendingUserInputQuestion = () => {
604
+ const { activePendingProgress } = readPendingUserInputDraft(draftScope);
605
if (!activePendingProgress) {
606
return;
607
}
@@ -526,10 +616,6 @@ export function usePendingThreadRequests(input: {
616
pendingUserInputs,
617
activePendingApproval,
618
activePendingUserInput,
529
- activePendingDraftAnswers,
530
- activePendingQuestionIndex,
531
- activePendingProgress,
532
- activePendingResolvedAnswers,
619
activePendingIsResponding,
620
respondingRequestIds,
621
onRespondToApproval: onRespondToApprovalStable,
apps/web/test/appScenarios.renders.tsx
+86
-2
@@ -4,9 +4,10 @@
4
// atoms the app reads. See renderScenarios.renders.tsx for the counting rules.
5
import { createMemoryHistory } from "@tanstack/react-router";
6
import { scopeProjectRef, scopeThreadRef } from "@t3tools/client-runtime/environment";
7
-import type { ThreadId } from "@t3tools/contracts";
7
+import { NodeId, RuntimeRequestId, TurnItemId, type ThreadId } from "@t3tools/contracts";
8
import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings";
9
import type * as Context from "effect/Context";
10
+import * as DateTime from "effect/DateTime";
11
import { AsyncResult } from "effect/reactivity";
12
import { expect, it, vi } from "vite-plus/test";
13
import { commands, page, userEvent } from "vite-plus/test/browser";
@@ -33,6 +34,7 @@ import {
34
threadWithHistory,
35
userItem,
36
type FakeDriver,
37
+ type FakeThread,
38
} from "./fakeEnvironment";
39
import { commitsSoFar, startCounting, stopCounting, type RenderReport } from "./renderCounter";
40
import { act, fakeTimers, render } from "./render";
@@ -74,7 +76,70 @@ const [WARM, A, B, LIVE] = THREADS.map((thread) => thread.id) as [
76
77
const SIDE_CHAT = { ...threadWithHistory("thread-side", HISTORY_TURNS), sideChatOf: WARM };
78
77
-installFakeEnvironment([...THREADS, SIDE_CHAT]);
79
+// The agent waits on two questions: an option to pick, then a typed answer. They take the same
80
+// height, so moving between them leaves the composer inset that ChatView lays out unchanged.
81
+const QUESTION_AT = DateTime.makeUnsafe("2026-03-17T19:12:28.000Z");
82
+const QUESTION_THREAD = threadWithHistory("thread-question", HISTORY_TURNS);
83
+const QUESTION_REQUEST = RuntimeRequestId.make("thread-question-request");
84
+const QUESTION = {
85
+ ...QUESTION_THREAD,
86
+ items: [
87
+ ...QUESTION_THREAD.items,
88
+ {
89
+ id: TurnItemId.make(QUESTION_REQUEST),
90
+ threadId: QUESTION_THREAD.id,
91
+ runId: null,
92
+ nodeId: NodeId.make(QUESTION_REQUEST),
93
+ providerThreadId: null,
94
+ providerTurnId: null,
95
+ nativeItemRef: null,
96
+ parentItemId: null,
97
+ ordinal: HISTORY_TURNS * 2,
98
+ status: "completed",
99
+ title: null,
100
+ startedAt: QUESTION_AT,
101
+ completedAt: QUESTION_AT,
102
+ updatedAt: QUESTION_AT,
103
+ type: "user_input_request",
104
+ requestId: QUESTION_REQUEST,
105
+ questions: [
106
+ {
107
+ id: "approach",
108
+ header: "Approach",
109
+ question: "Which approach should I take?",
110
+ options: [
111
+ { label: "Incremental", description: "One module at a time" },
112
+ { label: "Rewrite", description: "Everything at once" },
113
+ ],
114
+ },
115
+ {
116
+ id: "tests",
117
+ header: "Tests",
118
+ question: "Which tests should I run?",
119
+ options: [
120
+ { label: "Changed", description: "Only what this touches" },
121
+ { label: "All", description: "The whole suite" },
122
+ ],
123
+ },
124
+ ],
125
+ },
126
+ ],
127
+ runtimeRequests: [
128
+ {
129
+ id: QUESTION_REQUEST,
130
+ nodeId: NodeId.make(QUESTION_REQUEST),
131
+ providerTurnId: null,
132
+ nativeRequestRef: null,
133
+ kind: "user_input",
134
+ status: "pending",
135
+ responseCapability: { type: "message" },
136
+ createdAt: QUESTION_AT,
137
+ resolvedAt: null,
138
+ },
139
+ ],
140
+} satisfies FakeThread;
141
+
142
+installFakeEnvironment([...THREADS, SIDE_CHAT, QUESTION]);
143
// Desktop-sized, so the sidebar, composer and right panel lay out as they do in the app.
144
await page.viewport(1400, 900);
145
// A returning user: the first-run gate would otherwise wait on onboarding evidence.
@@ -279,6 +344,25 @@ it("app-type-in-composer", async () => {
344
await report("app-type-in-composer", [counted]);
345
});
346
347
+it("app-answer-question", async () => {
348
+ using _clock = frozenClock();
349
+ await using _app = (await openThread(QUESTION.id)).screen;
350
+ const pick = await measure(async () => {
351
+ await userEvent.click(page.getByRole("button", { name: /Incremental/ }));
352
+ await expect.element(page.getByText("Which tests should I run?")).toBeVisible();
353
+ });
354
+ const editor = page.getByTestId("composer-editor");
355
+ await userEvent.click(editor);
356
+ const type = await measure(async () => {
357
+ await userEvent.type(editor, TYPED_TEXT);
358
+ await expect.element(editor).toHaveTextContent(TYPED_TEXT);
359
+ });
360
+ // Answers live in the composer; the chat view renders for the request, not its answers.
361
+ expect(pick.components.ChatView).toBeUndefined();
362
+ expect(type.components.ChatView).toBeUndefined();
363
+ await report("app-answer-question", [pick, type]);
364
+});
365
+
366
it("app-switch-thread", async () => {
367
using _clock = frozenClock();
368
const { screen, router } = await openThread(A);