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 25, 11:00 UTC
Fix store selector consistency, memoize timelineMessages, and suppress false-positive lint warnings
- Hoist removeOrphanedTerminalStates to a top-level selector in EventRouter for consistency with other store selectors - Convert timelineMessages IIFE to useMemo with proper deps - Suppress no-map-spread in ChatView (spread is conditional, immutability required) - Suppress exhaustive-deps for autoFocus in TerminalViewport (mount-time only) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Julius Marminge committed
Mar 2, 2026 at 12:53 UTC
4e45c1a6abef59bc99ae1bea3c7a8be9d8775c66
3 files changed
+57
-32
apps/web/src/components/ChatView.tsx
+50
-28
@@ -474,7 +474,9 @@ export default function ChatView({ threadId }: ChatViewProps) {
474
const clearComposerDraftContent = useComposerDraftStore((store) => store.clearComposerContent);
475
const clearDraftThread = useComposerDraftStore((store) => store.clearDraftThread);
476
const setDraftThreadContext = useComposerDraftStore((store) => store.setDraftThreadContext);
477
- const draftThread = useComposerDraftStore((store) => store.draftThreadsByThreadId[threadId] ?? null);
477
+ const draftThread = useComposerDraftStore(
478
+ (store) => store.draftThreadsByThreadId[threadId] ?? null,
479
+ );
480
const promptRef = useRef(prompt);
481
const [isDragOverComposer, setIsDragOverComposer] = useState(false);
482
const [expandedImage, setExpandedImage] = useState<ExpandedImagePreview | null>(null);
@@ -604,7 +606,9 @@ export default function ChatView({ threadId }: ChatViewProps) {
606
markThreadVisited,
607
]);
608
607
- const baseThreadModel = resolveModelSlug(activeThread?.model ?? activeProject?.model ?? DEFAULT_MODEL);
609
+ const baseThreadModel = resolveModelSlug(
610
+ activeThread?.model ?? activeProject?.model ?? DEFAULT_MODEL,
611
+ );
612
const selectedModel = resolveModelSlug(composerDraft.model ?? baseThreadModel);
613
const selectedEffort = composerDraft.effort ?? DEFAULT_REASONING;
614
const modelOptions = getAppModelOptions(settings.customCodexModels, selectedModel);
@@ -614,8 +618,14 @@ export default function ChatView({ threadId }: ChatViewProps) {
618
const isWorking = phase === "running" || isSendBusy || isConnecting || isRevertingCheckpoint;
619
const nowIso = new Date(nowTick).toISOString();
620
const threadActivities = activeThread?.activities ?? [];
617
- const workLogEntries = deriveWorkLogEntries(threadActivities, activeLatestTurn?.turnId ?? undefined);
618
- const latestTurnHasToolActivity = hasToolActivityForTurn(threadActivities, activeLatestTurn?.turnId);
621
+ const workLogEntries = deriveWorkLogEntries(
622
+ threadActivities,
623
+ activeLatestTurn?.turnId ?? undefined,
624
+ );
625
+ const latestTurnHasToolActivity = hasToolActivityForTurn(
626
+ threadActivities,
627
+ activeLatestTurn?.turnId,
628
+ );
629
const pendingApprovals = derivePendingApprovals(threadActivities);
630
useEffect(() => {
631
attachmentPreviewHandoffByMessageIdRef.current = attachmentPreviewHandoffByMessageId;
@@ -680,13 +690,22 @@ export default function ChatView({ threadId }: ChatViewProps) {
690
delete attachmentPreviewHandoffTimeoutByMessageIdRef.current[messageId];
691
}, ATTACHMENT_PREVIEW_HANDOFF_TTL_MS);
692
}, []);
683
- const timelineMessages = (() => {
684
- const serverMessages = activeThread?.messages ?? [];
693
+ const serverMessages = activeThread?.messages;
694
+ const timelineMessages = useMemo(() => {
695
+ const messages = serverMessages ?? [];
696
const serverMessagesWithPreviewHandoff =
697
Object.keys(attachmentPreviewHandoffByMessageId).length === 0
687
- ? serverMessages
688
- : serverMessages.map((message) => {
689
- if (message.role !== "user" || !message.attachments || message.attachments.length === 0) {
698
+ ? messages
699
+ : // Spread only fires for the few messages that actually changed;
700
+ // unchanged ones early-return their original reference.
701
+ // In-place mutation would break React's immutable state contract.
702
+ // oxlint-disable-next-line no-map-spread
703
+ messages.map((message) => {
704
+ if (
705
+ message.role !== "user" ||
706
+ !message.attachments ||
707
+ message.attachments.length === 0
708
+ ) {
709
return message;
710
}
711
const handoffPreviewUrls = attachmentPreviewHandoffByMessageId[message.id];
@@ -724,7 +743,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
743
return serverMessagesWithPreviewHandoff;
744
}
745
return [...serverMessagesWithPreviewHandoff, ...pendingMessages];
727
- })();
746
+ }, [serverMessages, attachmentPreviewHandoffByMessageId, optimisticUserMessages]);
747
const timelineEntries = deriveTimelineEntries(timelineMessages, workLogEntries);
748
const { turnDiffSummaries, inferredCheckpointTurnCountByTurnId } =
749
useTurnDiffSummaries(activeThread);
@@ -937,8 +956,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
956
(activeThread.messages.length > 0 ||
957
(activeThread.session !== null && activeThread.session.status !== "closed")),
958
);
940
- const hasReachedTerminalLimit =
941
- terminalState.terminalIds.length >= MAX_THREAD_TERMINAL_COUNT;
959
+ const hasReachedTerminalLimit = terminalState.terminalIds.length >= MAX_THREAD_TERMINAL_COUNT;
960
const setThreadError = useCallback(
961
(targetThreadId: ThreadId | null, error: string | null) => {
962
if (!targetThreadId) return;
@@ -1390,12 +1408,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
1408
return () => {
1409
window.clearTimeout(timer);
1410
};
1393
- }, [
1394
- activeThread?.id,
1395
- activeThread?.messages,
1396
- handoffAttachmentPreviews,
1397
- optimisticUserMessages,
1398
- ]);
1411
+ }, [activeThread?.id, activeThread?.messages, handoffAttachmentPreviews, optimisticUserMessages]);
1412
1413
useEffect(() => {
1414
promptRef.current = prompt;
@@ -1810,7 +1823,10 @@ export default function ChatView({ threadId }: ChatViewProps) {
1823
const shouldCreateWorktree =
1824
isFirstMessage && envMode === "worktree" && !activeThread.worktreePath;
1825
if (shouldCreateWorktree && !activeThread.branch) {
1813
- setStoreThreadError(threadIdForSend, "Select a base branch before sending in New worktree mode.");
1826
+ setStoreThreadError(
1827
+ threadIdForSend,
1828
+ "Select a base branch before sending in New worktree mode.",
1829
+ );
1830
return;
1831
}
1832
@@ -1965,8 +1981,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
1981
setSendPhase("sending-turn");
1982
const turnAttachments = await turnAttachmentsPromise;
1983
const approvalPolicy = runtimeMode === "full-access" ? "never" : "on-request";
1968
- const sandboxMode =
1969
- runtimeMode === "full-access" ? "danger-full-access" : "workspace-write";
1984
+ const sandboxMode = runtimeMode === "full-access" ? "danger-full-access" : "workspace-write";
1985
await api.orchestration.dispatchCommand({
1986
type: "thread.turn.start",
1987
commandId: newCommandId(),
@@ -2169,11 +2184,14 @@ export default function ChatView({ threadId }: ChatViewProps) {
2184
workspaceEntriesQuery.isLoading ||
2185
workspaceEntriesQuery.isFetching);
2186
2172
- const onPromptChange = useCallback((nextPrompt: string, nextCursor: number) => {
2173
- promptRef.current = nextPrompt;
2174
- setPrompt(nextPrompt);
2175
- setComposerCursor(nextCursor);
2176
- }, [setComposerCursor, setPrompt]);
2187
+ const onPromptChange = useCallback(
2188
+ (nextPrompt: string, nextCursor: number) => {
2189
+ promptRef.current = nextPrompt;
2190
+ setPrompt(nextPrompt);
2191
+ setComposerCursor(nextCursor);
2192
+ },
2193
+ [setComposerCursor, setPrompt],
2194
+ );
2195
2196
const onKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
2197
if (composerMenuOpen && composerMenuItems.length > 0) {
@@ -2402,8 +2420,12 @@ export default function ChatView({ threadId }: ChatViewProps) {
2420
</span>
2421
}
2422
/>
2405
- <TooltipPopup side="top" className="max-w-64 whitespace-normal leading-tight">
2406
- Draft attachment could not be saved locally and may be lost on navigation.
2423
+ <TooltipPopup
2424
+ side="top"
2425
+ className="max-w-64 whitespace-normal leading-tight"
2426
+ >
2427
+ Draft attachment could not be saved locally and may be lost on
2428
+ navigation.
2429
</TooltipPopup>
2430
</Tooltip>
2431
)}
apps/web/src/components/ThreadTerminalDrawer.tsx
+3
@@ -389,6 +389,9 @@ function TerminalViewport({
389
fitAddonRef.current = null;
390
terminal.dispose();
391
};
392
+ // autoFocus is intentionally omitted;
393
+ // it is only read at mount time and must not trigger terminal teardown/recreation.
394
+ // eslint-disable-next-line react-hooks/exhaustive-deps
395
}, [cwd, runtimeEnv, terminalId, threadId]);
396
397
useEffect(() => {
apps/web/src/routes/__root.tsx
+4
-4
@@ -126,6 +126,9 @@ function errorDetails(error: unknown): string {
126
function EventRouter() {
127
const syncServerReadModel = useStore((store) => store.syncServerReadModel);
128
const setProjectExpanded = useStore((store) => store.setProjectExpanded);
129
+ const removeOrphanedTerminalStates = useTerminalStateStore(
130
+ (store) => store.removeOrphanedTerminalStates,
131
+ );
132
const queryClient = useQueryClient();
133
const navigate = useNavigate();
134
const pathname = useRouterState({ select: (state) => state.location.pathname });
@@ -143,9 +146,6 @@ function EventRouter() {
146
let syncing = false;
147
let pending = false;
148
146
- const removeOrphanedTerminalStates =
147
- useTerminalStateStore.getState().removeOrphanedTerminalStates;
148
-
149
const flushSnapshotSync = async (): Promise<void> => {
150
const snapshot = await api.orchestration.getSnapshot();
151
if (disposed) return;
@@ -276,7 +276,7 @@ function EventRouter() {
276
unsubWelcome();
277
unsubServerConfigUpdated();
278
};
279
- }, [navigate, queryClient, setProjectExpanded, syncServerReadModel]);
279
+ }, [navigate, queryClient, removeOrphanedTerminalStates, setProjectExpanded, syncServerReadModel]);
280
281
return null;
282
}