@devries-cameron20 / t3code Mirror · read-only / commits / d4c90d696d
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 25, 11:00 UTC

Simplify Zustand selectors by removing memoized callbacks

- Replace `useCallback`-wrapped `useStore` selectors with inline selectors - Apply across chat, diff, branch toolbar, and chat thread route components

Julius Marminge committed Mar 2, 2026 at 00:30 UTC d4c90d696d2546466d364cfccc86bcf2be6a7c86
4 files changed +23 -51
apps/web/src/components/BranchToolbar.tsx
+5 -9
@@ -1,6 +1,6 @@
1 import type { GitBranch, ThreadId } from "@t3tools/contracts";
2 import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
3 -import { useCallback, useEffect, useState } from "react";
3 +import { useEffect, useState } from "react";
4
5 import { newCommandId } from "../lib/utils";
6 import {
@@ -46,16 +46,12 @@ export default function BranchToolbar({
46 const setThreadBranchAction = useStore((state) => state.setThreadBranch);
47 const setThreadErrorAction = useStore((state) => state.setThreadError);
48 const draftThread = useComposerDraftStore((store) => store.getDraftThread(threadId));
49 - const serverThread = useStore(
50 - useCallback((state) => state.threads.find((thread) => thread.id === threadId), [threadId]),
49 + const serverThread = useStore((state) =>
50 + state.threads.find((thread) => thread.id === threadId),
51 );
52 const activeProjectId = serverThread?.projectId ?? draftThread?.projectId ?? null;
53 - const activeProject = useStore(
54 - useCallback(
55 - (state) =>
56 - activeProjectId ? state.projects.find((project) => project.id === activeProjectId) : undefined,
57 - [activeProjectId],
58 - ),
53 + const activeProject = useStore((state) =>
54 + activeProjectId ? state.projects.find((project) => project.id === activeProjectId) : undefined,
55 );
56 const setDraftThreadContext = useComposerDraftStore((store) => store.setDraftThreadContext);
57 const queryClient = useQueryClient();
apps/web/src/components/ChatView.tsx
+12 -28
@@ -490,18 +490,14 @@ export default function ChatView({ threadId }: ChatViewProps) {
490 const clearDraftThread = useComposerDraftStore((store) => store.clearDraftThread);
491 const setDraftThreadContext = useComposerDraftStore((store) => store.setDraftThreadContext);
492 const draftThread = useComposerDraftStore((store) => store.draftThreadsByThreadId[threadId] ?? null);
493 - const serverThread = useStore(
494 - useCallback((state) => state.threads.find((thread) => thread.id === threadId), [threadId]),
493 + const serverThread = useStore((state) =>
494 + state.threads.find((thread) => thread.id === threadId),
495 );
496 const fallbackDraftProjectId = draftThread?.projectId ?? null;
497 - const fallbackDraftProject = useStore(
498 - useCallback(
499 - (state) =>
500 - fallbackDraftProjectId
501 - ? state.projects.find((project) => project.id === fallbackDraftProjectId)
502 - : undefined,
503 - [fallbackDraftProjectId],
504 - ),
497 + const fallbackDraftProject = useStore((state) =>
498 + fallbackDraftProjectId
499 + ? state.projects.find((project) => project.id === fallbackDraftProjectId)
500 + : undefined,
501 );
502 const promptRef = useRef(prompt);
503 const [isDragOverComposer, setIsDragOverComposer] = useState(false);
@@ -601,12 +597,8 @@ export default function ChatView({ threadId }: ChatViewProps) {
597 const activeLatestTurn = activeThread?.latestTurn ?? null;
598 const latestTurnSettled = isLatestTurnSettled(activeLatestTurn, activeThread?.session ?? null);
599 const activeProjectId = activeThread?.projectId ?? null;
604 - const activeProject = useStore(
605 - useCallback(
606 - (state) =>
607 - activeProjectId ? state.projects.find((project) => project.id === activeProjectId) : undefined,
608 - [activeProjectId],
609 - ),
600 + const activeProject = useStore((state) =>
601 + activeProjectId ? state.projects.find((project) => project.id === activeProjectId) : undefined,
602 );
603
604 useEffect(() => {
@@ -3541,20 +3533,12 @@ const OpenInPicker = memo(function OpenInPicker({
3533 ] satisfies { label: string; Icon: Icon; value: EditorId }[];
3534 const primaryOption = options.find(({ value }) => value === lastEditor);
3535
3544 - const activeThread = useStore(
3545 - useCallback(
3546 - (state) =>
3547 - activeThreadId ? state.threads.find((thread) => thread.id === activeThreadId) : undefined,
3548 - [activeThreadId],
3549 - ),
3536 + const activeThread = useStore((state) =>
3537 + activeThreadId ? state.threads.find((thread) => thread.id === activeThreadId) : undefined,
3538 );
3539 const activeProjectId = activeThread?.projectId ?? null;
3552 - const activeProject = useStore(
3553 - useCallback(
3554 - (state) =>
3555 - activeProjectId ? state.projects.find((project) => project.id === activeProjectId) : undefined,
3556 - [activeProjectId],
3557 - ),
3540 + const activeProject = useStore((state) =>
3541 + activeProjectId ? state.projects.find((project) => project.id === activeProjectId) : undefined,
3542 );
3543
3544 const openInEditor = useCallback(
apps/web/src/components/DiffPanel.tsx
+4 -12
@@ -167,20 +167,12 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
167 });
168 const diffSearch = useSearch({ strict: false, select: (search) => parseDiffRouteSearch(search) });
169 const activeThreadId = routeThreadId;
170 - const activeThread = useStore(
171 - useCallback(
172 - (state) =>
173 - activeThreadId ? state.threads.find((thread) => thread.id === activeThreadId) : undefined,
174 - [activeThreadId],
175 - ),
170 + const activeThread = useStore((state) =>
171 + activeThreadId ? state.threads.find((thread) => thread.id === activeThreadId) : undefined,
172 );
173 const activeProjectId = activeThread?.projectId ?? null;
178 - const activeProject = useStore(
179 - useCallback(
180 - (state) =>
181 - activeProjectId ? state.projects.find((project) => project.id === activeProjectId) : undefined,
182 - [activeProjectId],
183 - ),
174 + const activeProject = useStore((state) =>
175 + activeProjectId ? state.projects.find((project) => project.id === activeProjectId) : undefined,
176 );
177 const activeCwd = activeThread?.worktreePath ?? activeProject?.cwd;
178 const { turnDiffSummaries, inferredCheckpointTurnCountByTurnId } =
apps/web/src/routes/_chat.$threadId.tsx
+2 -2
@@ -139,8 +139,8 @@ function ChatThreadRouteView() {
139 select: (params) => ThreadId.makeUnsafe(params.threadId),
140 });
141 const search = Route.useSearch();
142 - const threadExists = useStore(
143 - useCallback((state) => state.threads.some((thread) => thread.id === threadId), [threadId]),
142 + const threadExists = useStore((state) =>
143 + state.threads.some((thread) => thread.id === threadId),
144 );
145 const draftThreadExists = useComposerDraftStore(
146 (store) => Object.hasOwn(store.draftThreadsByThreadId, threadId),