Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
Simplify Zustand selectors by removing memoized callbacks
Julius Marminged4c90d696d25
diff --git a/apps/web/src/components/BranchToolbar.tsx b/apps/web/src/components/BranchToolbar.tsxindex 564eea541..57bee94c6 100644--- a/apps/web/src/components/BranchToolbar.tsx+++ b/apps/web/src/components/BranchToolbar.tsx@@ -1,6 +1,6 @@import type { GitBranch, ThreadId } from "@t3tools/contracts";import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";-import { useCallback, useEffect, useState } from "react";+import { useEffect, useState } from "react";import { newCommandId } from "../lib/utils";import {@@ -46,16 +46,12 @@ export default function BranchToolbar({const setThreadBranchAction = useStore((state) => state.setThreadBranch);const setThreadErrorAction = useStore((state) => state.setThreadError);const draftThread = useComposerDraftStore((store) => store.getDraftThread(threadId));- const serverThread = useStore(- useCallback((state) => state.threads.find((thread) => thread.id === threadId), [threadId]),+ const serverThread = useStore((state) =>+ state.threads.find((thread) => thread.id === threadId),);const activeProjectId = serverThread?.projectId ?? draftThread?.projectId ?? null;- const activeProject = useStore(- useCallback(- (state) =>- activeProjectId ? state.projects.find((project) => project.id === activeProjectId) : undefined,- [activeProjectId],- ),+ const activeProject = useStore((state) =>+ activeProjectId ? state.projects.find((project) => project.id === activeProjectId) : undefined,);const setDraftThreadContext = useComposerDraftStore((store) => store.setDraftThreadContext);const queryClient = useQueryClient();diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsxindex 74f10378d..338dd7240 100644--- a/apps/web/src/components/ChatView.tsx+++ b/apps/web/src/components/ChatView.tsx@@ -490,18 +490,14 @@ export default function ChatView({ threadId }: ChatViewProps) {const clearDraftThread = useComposerDraftStore((store) => store.clearDraftThread);const setDraftThreadContext = useComposerDraftStore((store) => store.setDraftThreadContext);const draftThread = useComposerDraftStore((store) => store.draftThreadsByThreadId[threadId] ?? null);- const serverThread = useStore(- useCallback((state) => state.threads.find((thread) => thread.id === threadId), [threadId]),+ const serverThread = useStore((state) =>+ state.threads.find((thread) => thread.id === threadId),);const fallbackDraftProjectId = draftThread?.projectId ?? null;- const fallbackDraftProject = useStore(- useCallback(- (state) =>- fallbackDraftProjectId- ? state.projects.find((project) => project.id === fallbackDraftProjectId)- : undefined,- [fallbackDraftProjectId],- ),+ const fallbackDraftProject = useStore((state) =>+ fallbackDraftProjectId+ ? state.projects.find((project) => project.id === fallbackDraftProjectId)+ : undefined,);const promptRef = useRef(prompt);const [isDragOverComposer, setIsDragOverComposer] = useState(false);@@ -601,12 +597,8 @@ export default function ChatView({ threadId }: ChatViewProps) {const activeLatestTurn = activeThread?.latestTurn ?? null;const latestTurnSettled = isLatestTurnSettled(activeLatestTurn, activeThread?.session ?? null);const activeProjectId = activeThread?.projectId ?? null;- const activeProject = useStore(- useCallback(- (state) =>- activeProjectId ? state.projects.find((project) => project.id === activeProjectId) : undefined,- [activeProjectId],- ),+ const activeProject = useStore((state) =>+ activeProjectId ? state.projects.find((project) => project.id === activeProjectId) : undefined,);useEffect(() => {@@ -3541,20 +3533,12 @@ const OpenInPicker = memo(function OpenInPicker({] satisfies { label: string; Icon: Icon; value: EditorId }[];const primaryOption = options.find(({ value }) => value === lastEditor);- const activeThread = useStore(- useCallback(- (state) =>- activeThreadId ? state.threads.find((thread) => thread.id === activeThreadId) : undefined,- [activeThreadId],- ),+ const activeThread = useStore((state) =>+ activeThreadId ? state.threads.find((thread) => thread.id === activeThreadId) : undefined,);const activeProjectId = activeThread?.projectId ?? null;- const activeProject = useStore(- useCallback(- (state) =>- activeProjectId ? state.projects.find((project) => project.id === activeProjectId) : undefined,- [activeProjectId],- ),+ const activeProject = useStore((state) =>+ activeProjectId ? state.projects.find((project) => project.id === activeProjectId) : undefined,);const openInEditor = useCallback(diff --git a/apps/web/src/components/DiffPanel.tsx b/apps/web/src/components/DiffPanel.tsxindex 99b2d5180..8a963c6e2 100644--- a/apps/web/src/components/DiffPanel.tsx+++ b/apps/web/src/components/DiffPanel.tsx@@ -167,20 +167,12 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {});const diffSearch = useSearch({ strict: false, select: (search) => parseDiffRouteSearch(search) });const activeThreadId = routeThreadId;- const activeThread = useStore(- useCallback(- (state) =>- activeThreadId ? state.threads.find((thread) => thread.id === activeThreadId) : undefined,- [activeThreadId],- ),+ const activeThread = useStore((state) =>+ activeThreadId ? state.threads.find((thread) => thread.id === activeThreadId) : undefined,);const activeProjectId = activeThread?.projectId ?? null;- const activeProject = useStore(- useCallback(- (state) =>- activeProjectId ? state.projects.find((project) => project.id === activeProjectId) : undefined,- [activeProjectId],- ),+ const activeProject = useStore((state) =>+ activeProjectId ? state.projects.find((project) => project.id === activeProjectId) : undefined,);const activeCwd = activeThread?.worktreePath ?? activeProject?.cwd;const { turnDiffSummaries, inferredCheckpointTurnCountByTurnId } =diff --git a/apps/web/src/routes/_chat.$threadId.tsx b/apps/web/src/routes/_chat.$threadId.tsxindex 14d832e7a..ce8ec5aec 100644--- a/apps/web/src/routes/_chat.$threadId.tsx+++ b/apps/web/src/routes/_chat.$threadId.tsx@@ -139,8 +139,8 @@ function ChatThreadRouteView() {select: (params) => ThreadId.makeUnsafe(params.threadId),});const search = Route.useSearch();- const threadExists = useStore(- useCallback((state) => state.threads.some((thread) => thread.id === threadId), [threadId]),+ const threadExists = useStore((state) =>+ state.threads.some((thread) => thread.id === threadId),);const draftThreadExists = useComposerDraftStore((store) => Object.hasOwn(store.draftThreadsByThreadId, threadId),