| author | |
| committer | |
| log | d4c90d696d2546466d364cfccc86bcf2be6a7c86 |
| tree | 478277e9ca05405bcd84389b9a2e41ca74b33421 |
| parent | be4d26a1b31d96754bdadc2ab7094dfdc9c7bad9 |
- Replace `useCallback`-wrapped `useStore` selectors with inline selectors
- Apply across chat, diff, branch toolbar, and chat thread route components4 files changed, 23 insertions(+), 51 deletions(-)
apps/web/src/components/BranchToolbar.tsx+5-9| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | import type { GitBranch, ThreadId } from "@t3tools/contracts"; |
| 2 | 2 | import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; |
| 3 | import { useCallback, useEffect, useState } from "react"; | |
| 3 | import { useEffect, useState } from "react"; | |
| 4 | 4 | |
| 5 | 5 | import { newCommandId } from "../lib/utils"; |
| 6 | 6 | import { |
| ... | ... | @@ -46,16 +46,12 @@ export default function BranchToolbar({ |
| 46 | 46 | const setThreadBranchAction = useStore((state) => state.setThreadBranch); |
| 47 | 47 | const setThreadErrorAction = useStore((state) => state.setThreadError); |
| 48 | 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 | 51 | ); |
| 52 | 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, | |
| 59 | 55 | ); |
| 60 | 56 | const setDraftThreadContext = useComposerDraftStore((store) => store.setDraftThreadContext); |
| 61 | 57 | const queryClient = useQueryClient(); |
apps/web/src/components/ChatView.tsx+12-28| ... | ... | @@ -490,18 +490,14 @@ export default function ChatView({ threadId }: ChatViewProps) { |
| 490 | 490 | const clearDraftThread = useComposerDraftStore((store) => store.clearDraftThread); |
| 491 | 491 | const setDraftThreadContext = useComposerDraftStore((store) => store.setDraftThreadContext); |
| 492 | 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 | 495 | ); |
| 496 | 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, | |
| 505 | 501 | ); |
| 506 | 502 | const promptRef = useRef(prompt); |
| 507 | 503 | const [isDragOverComposer, setIsDragOverComposer] = useState(false); |
| ... | ... | @@ -601,12 +597,8 @@ export default function ChatView({ threadId }: ChatViewProps) { |
| 601 | 597 | const activeLatestTurn = activeThread?.latestTurn ?? null; |
| 602 | 598 | const latestTurnSettled = isLatestTurnSettled(activeLatestTurn, activeThread?.session ?? null); |
| 603 | 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, | |
| 610 | 602 | ); |
| 611 | 603 | |
| 612 | 604 | useEffect(() => { |
| ... | ... | @@ -3541,20 +3533,12 @@ const OpenInPicker = memo(function OpenInPicker({ |
| 3541 | 3533 | ] satisfies { label: string; Icon: Icon; value: EditorId }[]; |
| 3542 | 3534 | const primaryOption = options.find(({ value }) => value === lastEditor); |
| 3543 | 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, | |
| 3550 | 3538 | ); |
| 3551 | 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, | |
| 3558 | 3542 | ); |
| 3559 | 3543 | |
| 3560 | 3544 | const openInEditor = useCallback( |
apps/web/src/components/DiffPanel.tsx+4-12| ... | ... | @@ -167,20 +167,12 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) { |
| 167 | 167 | }); |
| 168 | 168 | const diffSearch = useSearch({ strict: false, select: (search) => parseDiffRouteSearch(search) }); |
| 169 | 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, | |
| 176 | 172 | ); |
| 177 | 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, | |
| 184 | 176 | ); |
| 185 | 177 | const activeCwd = activeThread?.worktreePath ?? activeProject?.cwd; |
| 186 | 178 | const { turnDiffSummaries, inferredCheckpointTurnCountByTurnId } = |
apps/web/src/routes/_chat.$threadId.tsx+2-2| ... | ... | @@ -139,8 +139,8 @@ function ChatThreadRouteView() { |
| 139 | 139 | select: (params) => ThreadId.makeUnsafe(params.threadId), |
| 140 | 140 | }); |
| 141 | 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 | 144 | ); |
| 145 | 145 | const draftThreadExists = useComposerDraftStore( |
| 146 | 146 | (store) => Object.hasOwn(store.draftThreadsByThreadId, threadId), |