Skip to content

Commit f167a00

Browse files
OmarAlex24claude
andcommitted
perf(web): answering a question no longer re-renders the whole chat view
ChatView subscribed to the open question's draft answers, position and attachment state, so every keystroke in a custom answer, every option click and every move between questions re-rendered the whole chat view, its timeline and the details panel. Typing in the normal composer does not. The per-question draft subscriptions and the progress derived from them now live in usePendingUserInputDraft, which ChatComposer calls. ChatView keeps the pending request list, responding state and the request callbacks; the callbacks that need the current answers (advance, previous, select option) read the draft stores when called. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 4cb6945 commit f167a00

9 files changed

Lines changed: 303 additions & 139 deletions

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,10 +1344,6 @@ export default function ChatView(props: ChatViewProps) {
13441344
pendingUserInputs,
13451345
activePendingApproval,
13461346
activePendingUserInput,
1347-
activePendingDraftAnswers,
1348-
activePendingQuestionIndex,
1349-
activePendingProgress,
1350-
activePendingResolvedAnswers,
13511347
activePendingIsResponding,
13521348
respondingRequestIds,
13531349
onRespondToApproval: onRespondToApprovalStable,
@@ -2967,7 +2963,7 @@ export default function ChatView(props: ChatViewProps) {
29672963
readPendingEnvironmentChange,
29682964
pendingApprovals,
29692965
respondingRequestIds,
2970-
activePendingProgress,
2966+
activePendingUserInput,
29712967
onAdvanceActivePendingUserInput,
29722968
onRespondToApproval: onRespondToApprovalStable,
29732969
beginLocalDispatch,
@@ -3082,7 +3078,7 @@ export default function ChatView(props: ChatViewProps) {
30823078
clientSettingsHydrated &&
30833079
!needsLoadBalancing &&
30843080
!activeEnvironmentUnavailable &&
3085-
!activePendingProgress &&
3081+
!activePendingUserInput &&
30863082
!feedbackUploading;
30873083
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- switches the draft to local mode, then resends the waiting message once sending is idle
30883084
useEffect(() => {
@@ -3691,11 +3687,7 @@ export default function ChatView(props: ChatViewProps) {
36913687
pendingApprovals={pendingApprovals}
36923688
onHeldRequestIdsChange={onHeldRequestIdsChange}
36933689
pendingUserInputs={pendingUserInputs}
3694-
activePendingProgress={activePendingProgress}
3695-
activePendingResolvedAnswers={activePendingResolvedAnswers}
36963690
activePendingIsResponding={activePendingIsResponding}
3697-
activePendingDraftAnswers={activePendingDraftAnswers}
3698-
activePendingQuestionIndex={activePendingQuestionIndex}
36993691
respondingRequestIds={respondingRequestIds}
37003692
showPlanFollowUpPrompt={showPlanFollowUpPrompt}
37013693
activeProposedPlan={activeProposedPlan}

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ import { type AppModelOption, getAppModelOptionsForInstance } from "../../modelS
247247
import type { UnifiedSettings } from "@t3tools/contracts/settings";
248248
import { isVideoAttachment, type SessionPhase, type Thread, type ThreadShell } from "../../types";
249249
import { type ComposerPromptHistoryPosition } from "./composerPromptHistory";
250-
import type { PendingUserInputDraftAnswer } from "@t3tools/client-runtime/state/pending-user-input";
250+
import { usePendingUserInputDraft } from "./usePendingThreadRequests";
251251
import type {
252252
LatestProposedPlanState,
253253
PendingApproval,
@@ -400,22 +400,7 @@ export interface ChatComposerProps {
400400
pendingApprovals: PendingApproval[];
401401
onHeldRequestIdsChange: (requestIds: ReadonlySet<string>) => void;
402402
pendingUserInputs: PendingUserInput[];
403-
activePendingProgress: {
404-
questionIndex: number;
405-
isLastQuestion: boolean;
406-
canAdvance: boolean;
407-
customAnswer: string;
408-
activeQuestion: {
409-
id: string;
410-
initialAnswer?: string | undefined;
411-
multiSelect?: boolean | undefined;
412-
allowCustomAnswer?: boolean | undefined;
413-
} | null;
414-
} | null;
415-
activePendingResolvedAnswers: Record<string, unknown> | null;
416403
activePendingIsResponding: boolean;
417-
activePendingDraftAnswers: Record<string, PendingUserInputDraftAnswer>;
418-
activePendingQuestionIndex: number;
419404
respondingRequestIds: RuntimeRequestId[];
420405

421406
showPlanFollowUpPrompt: boolean;
@@ -544,11 +529,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
544529
pendingApprovals,
545530
onHeldRequestIdsChange,
546531
pendingUserInputs: incomingPendingUserInputs,
547-
activePendingProgress: incomingPendingProgress,
548-
activePendingResolvedAnswers,
549532
activePendingIsResponding: incomingPendingIsResponding,
550-
activePendingDraftAnswers,
551-
activePendingQuestionIndex,
552533
respondingRequestIds,
553534
showPlanFollowUpPrompt,
554535
activeProposedPlan,
@@ -614,6 +595,17 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
614595
contextWindowLiveUsage,
615596
contextWindowProviderThread,
616597
);
598+
const {
599+
activePendingProgress: incomingPendingProgress,
600+
activePendingResolvedAnswers,
601+
activePendingDraftAnswers,
602+
activePendingQuestionIndex,
603+
} = usePendingUserInputDraft({
604+
environmentId,
605+
activeThreadId,
606+
activePendingUserInput: incomingPendingUserInputs[0] ?? null,
607+
supportsQuestionAttachments,
608+
});
617609
const primaryEnvironmentId = usePrimaryEnvironmentId();
618610
const composerDraftTargetKey = composerTargetKey(composerDraftTarget);
619611
const {

‎apps/web/src/components/chat/ComposerPendingUserInputPanel.navigation.browser.test.tsx‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { act, fakeTimers, render } from "../../../test/render";
2020
import { useComposerDraftStore } from "../../composerDraftStore";
2121
import { makeThreadProjectionFixture } from "../../test-fixtures";
2222
import { toastManager } from "../ui/toast";
23-
import { usePendingThreadRequests } from "./usePendingThreadRequests";
23+
import { usePendingThreadRequests, usePendingUserInputDraft } from "./usePendingThreadRequests";
2424

2525
const threadRef = { environmentId: EnvironmentId.make("env"), threadId: ThreadId.make("thread") };
2626

@@ -85,7 +85,7 @@ interface ProbeProps {
8585
function useProbeRequests({ environmentId, projection, loading = false }: ProbeProps) {
8686
const promptRef = useRef("");
8787
const composerRef = useRef(null);
88-
return usePendingThreadRequests({
88+
const requests = usePendingThreadRequests({
8989
environmentId,
9090
activeThreadId: projection.thread.id,
9191
serverProjection: loading ? null : projection,
@@ -97,9 +97,16 @@ function useProbeRequests({ environmentId, projection, loading = false }: ProbeP
9797
composerRef,
9898
setThreadError: () => {},
9999
});
100+
const draft = usePendingUserInputDraft({
101+
environmentId,
102+
activeThreadId: projection.thread.id,
103+
activePendingUserInput: requests.activePendingUserInput,
104+
supportsQuestionAttachments: false,
105+
});
106+
return { ...requests, ...draft };
100107
}
101108

102-
let requests: ReturnType<typeof usePendingThreadRequests>;
109+
let requests: ReturnType<typeof useProbeRequests>;
103110

104111
function PendingRequestsProbe(props: ProbeProps) {
105112
const state = useProbeRequests(props);

‎apps/web/src/components/chat/useComposerAttachmentIntake.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
composerFileNeedsReattach,
1919
} from "../../composerDraftStore";
2020
import { type ComposerPromptEditorHandle } from "../ComposerPromptEditorTiptap";
21+
import type { PendingUserInputProgress } from "../../pendingUserInput";
2122
import { type PendingUserInput } from "../../session-logic";
2223
import {
2324
changeQuestionAttachmentPreparation,
@@ -58,7 +59,7 @@ import {
5859
*/
5960
export function useComposerAttachmentIntake(input: {
6061
readonly activeThreadId: ChatComposerProps["activeThreadId"];
61-
readonly activePendingProgress: ChatComposerProps["activePendingProgress"];
62+
readonly activePendingProgress: PendingUserInputProgress | null;
6263
readonly activePendingIsResponding: boolean;
6364
readonly pendingUserInputs: ReadonlyArray<PendingUserInput>;
6465
readonly supportsQuestionAttachments: boolean;

‎apps/web/src/components/chat/useComposerSend.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ interface ComposerSendInput {
221221
readonly readPendingEnvironmentChange: DraftEnvironmentRouting["readPendingEnvironmentChange"];
222222
readonly pendingApprovals: PendingThreadRequests["pendingApprovals"];
223223
readonly respondingRequestIds: PendingThreadRequests["respondingRequestIds"];
224-
readonly activePendingProgress: PendingThreadRequests["activePendingProgress"];
224+
readonly activePendingUserInput: PendingThreadRequests["activePendingUserInput"];
225225
readonly onAdvanceActivePendingUserInput: PendingThreadRequests["onAdvanceActivePendingUserInput"];
226226
readonly onRespondToApproval: PendingThreadRequests["onRespondToApproval"];
227227
readonly beginLocalDispatch: LocalDispatchState["beginLocalDispatch"];
@@ -317,7 +317,7 @@ export function useComposerSend(input: ComposerSendInput) {
317317
readPendingEnvironmentChange,
318318
pendingApprovals,
319319
respondingRequestIds,
320-
activePendingProgress,
320+
activePendingUserInput,
321321
onAdvanceActivePendingUserInput,
322322
onRespondToApproval: onRespondToApprovalStable,
323323
beginLocalDispatch,
@@ -493,7 +493,7 @@ export function useComposerSend(input: ComposerSendInput) {
493493
? parseSideChatCommand(promptAtSend)
494494
: null;
495495
const answeringQuestion =
496-
Boolean(activePendingProgress) && sendCtx?.answeringPendingUserInput !== false;
496+
Boolean(activePendingUserInput) && sendCtx?.answeringPendingUserInput !== false;
497497
// Where side chats are unavailable, `/side` text can still be a literal answer.
498498
if (sideChatDisabledReason !== null && sideChatCommand && !answeringQuestion) {
499499
toastManager.add(

‎apps/web/src/components/chat/useComposerStash.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
partitionStashAttachments,
2626
usePromptStashStore,
2727
} from "../../promptStashStore";
28+
import type { PendingUserInputProgress } from "../../pendingUserInput";
2829
import { type PendingUserInput } from "../../session-logic";
2930
import { type ReviewCommentContext } from "../../reviewCommentContext";
3031
import { collapseExpandedComposerCursor } from "../../composer-logic";
@@ -77,7 +78,7 @@ export function useComposerStash(input: {
7778
readonly routeThreadRef: ChatComposerProps["routeThreadRef"];
7879
readonly projectSelectionRequired: boolean;
7980
readonly pendingUserInputs: ReadonlyArray<PendingUserInput>;
80-
readonly activePendingProgress: ChatComposerProps["activePendingProgress"];
81+
readonly activePendingProgress: PendingUserInputProgress | null;
8182
readonly prompt: string;
8283
readonly composerMenuOpen: boolean;
8384
readonly isComposerCollapsedMobile: boolean;

0 commit comments

Comments
 (0)