The best way to control Claude Code, Codex and more from any computer or phone
perf(web): router updates no longer re-render thread route consumers (#20837)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 17, 2026 at 02:04 UTC
489d08a0549428d3baefd10e610003c10d60e5ef
9 files changed
+53
-59
apps/web/src/components/AppSidebarLayout.tsx
+3
-6
@@ -7,7 +7,7 @@ import {
7
type CSSProperties,
8
type ReactNode,
9
} from "react";
10
-import { useLocation, useNavigate, useParams } from "@tanstack/react-router";
10
+import { useLocation, useNavigate } from "@tanstack/react-router";
11
12
import { isElectron } from "../env";
13
import { getLocalStorageItem, removeLocalStorageItem } from "../hooks/useLocalStorage";
@@ -22,7 +22,6 @@ import { isTerminalFocused } from "../lib/terminalFocus";
22
import { isModelPickerOpen } from "../modelPickerVisibility";
23
import { selectActiveRightPanel, useRightPanelStore } from "../rightPanelStore";
24
import { selectThreadTerminalUiState, useTerminalUiStateStore } from "../terminalUiStateStore";
25
-import { resolveThreadRouteRef } from "../threadRoutes";
25
import { cn, isMacPlatform } from "../lib/utils";
26
import { primaryServerKeybindingsAtom } from "../state/server";
27
import { useEnvironmentIdentificationMode, useLegacySidebarEnabled } from "../hooks/useSettings";
@@ -56,6 +55,7 @@ import {
55
useSidebarVisibility,
56
} from "./ui/sidebar";
57
import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
58
+import { useThreadRouteRef } from "../hooks/useThreadRouteTarget";
59
60
const MACOS_TRAFFIC_LIGHTS_LEFT_INSET = "var(--desktop-window-controls-inset, 90px)";
61
@@ -201,10 +201,7 @@ function SidebarControl() {
201
202
function NavigationHistoryShortcuts() {
203
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
204
- const routeThreadRef = useParams({
205
- strict: false,
206
- select: (params) => resolveThreadRouteRef(params),
207
- });
204
+ const routeThreadRef = useThreadRouteRef();
205
206
useEffect(() => {
207
const onKeyDown = (event: KeyboardEvent) => {
apps/web/src/components/CommandPalette.tsx
+5
-10
@@ -55,7 +55,7 @@ import {
55
PRIMARY_LOCAL_ENVIRONMENT_ID,
56
resolveEnvironmentMachineKind,
57
} from "@t3tools/contracts";
58
-import { useLocation, useNavigate, useParams } from "@tanstack/react-router";
58
+import { useLocation, useNavigate } from "@tanstack/react-router";
59
import {
60
ArrowLeftIcon,
61
ChartNoAxesColumnIcon,
@@ -161,7 +161,7 @@ import {
161
newProjectId,
162
} from "../lib/utils";
163
import { selectThreadTerminalUiState, useTerminalUiStateStore } from "../terminalUiStateStore";
164
-import { buildThreadRouteParams, resolveThreadRouteTarget } from "../threadRoutes";
164
+import { buildThreadRouteParams } from "../threadRoutes";
165
import { useAvailableSettingsSearchItems } from "./settings/useAvailableSettingsSearchItems";
166
import {
167
applyWslEnvironmentConfiguration,
@@ -245,6 +245,7 @@ import {
245
import type { Project } from "../types";
246
import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
247
import { readPullRequestListPreferences } from "~/components/pullRequest/pullRequestListPreferences";
248
+import { useThreadRouteTarget } from "../hooks/useThreadRouteTarget";
249
250
const EMPTY_BROWSE_ENTRIES: FilesystemBrowseResult["entries"] = [];
251
@@ -494,10 +495,7 @@ export function CommandPalette({ children }: { children: ReactNode }) {
495
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
496
const { theme, themeHalves, resolvedTheme, appearanceMode, setAppearanceMode } = useTheme();
497
const composerHandleRef = useRef<ChatComposerHandle | null>(null);
497
- const routeTarget = useParams({
498
- strict: false,
499
- select: (params) => resolveThreadRouteTarget(params),
500
- });
498
+ const routeTarget = useThreadRouteTarget();
499
const routeThreadRef = routeTarget?.kind === "server" ? routeTarget.threadRef : null;
500
const terminalOpen = useTerminalUiStateStore((state) =>
501
routeThreadRef
@@ -745,10 +743,7 @@ function OpenCommandPaletteDialog(props: {
743
const availableSettingsSearchItems = useAvailableSettingsSearchItems();
744
const { activeDraftThread, activeThread, defaultProjectRef, handleNewThread } =
745
useHandleNewThread();
748
- const paletteRouteTarget = useParams({
749
- strict: false,
750
- select: (params) => resolveThreadRouteTarget(params),
751
- });
746
+ const paletteRouteTarget = useThreadRouteTarget();
747
const projects = useProjects();
748
const referenceThreadRef =
749
pathname === "/pull-requests"
apps/web/src/components/DiffPanel.tsx
+2
-6
@@ -1,7 +1,6 @@
1
import { RefreshIcon } from "~/components/ui/refresh-icon";
2
import { useAtomValue } from "@effect/atom-react";
3
import type { FileDiffContentsLoader, FileDiffMetadata } from "@pierre/diffs";
4
-import { useParams } from "@tanstack/react-router";
4
import {
5
isAtomCommandInterrupted,
6
squashAtomCommandFailure,
@@ -47,7 +46,6 @@ import { PREFERRED_HIGHLIGHTER } from "../lib/syntaxHighlighting";
46
import { areAllDiffFilesCollapsed, toggleAllDiffFiles } from "../lib/diffCollapse";
47
import { useWorkspaceMutationRefresh } from "../hooks/useWorkspaceMutationRefresh";
48
import { useProject, useThreadCheckpointSummaries, useThreadShell } from "../state/entities";
50
-import { resolveThreadRouteRef } from "../threadRoutes";
49
import { useClientSettings, useUpdateClientSettings } from "../hooks/useSettings";
50
import { formatShortTimestamp } from "../timestampFormat";
51
import { DiffFilePathCopyButton } from "./DiffFilePathCopyButton";
@@ -91,6 +89,7 @@ import { createGitDiffFileContentsLoader } from "../lib/diffFileContents";
89
import { useReviewFilePatches } from "./diffs/useReviewFilePatches";
90
import { DiffFileLoadingBoundary } from "./diffs/DiffFileLoadingBoundary";
91
import { DiffFileStatus } from "./diffs/DiffFileStatus";
92
+import { useThreadRouteRef } from "../hooks/useThreadRouteTarget";
93
94
type DiffThemeType = "light" | "dark";
95
const AUTOMATIC_BASE_REF = "__automatic_base_ref__";
@@ -215,10 +214,7 @@ export default function DiffPanel({
214
const [codeViewRevision, setCodeViewRevision] = useState(0);
215
const [codeView, setCodeView] = useState<AnnotatableCodeViewHandle | null>(null);
216
218
- const routeThreadRef = useParams({
219
- strict: false,
220
- select: (params) => resolveThreadRouteRef(params),
221
- });
217
+ const routeThreadRef = useThreadRouteRef();
218
const activeThreadId = routeThreadRef?.threadId ?? null;
219
const activeThread = useThreadShell(routeThreadRef);
220
const fileAccess = useFilesystemReadAccess(activeThread?.environmentId ?? null);
apps/web/src/components/LegacySidebar.tsx
+4
-10
@@ -68,7 +68,7 @@ import {
68
squashAtomCommandFailure,
69
} from "@t3tools/client-runtime/state/runtime";
70
import { threadRuntimeCanArchive } from "@t3tools/client-runtime/state/models";
71
-import { useNavigate, useParams, useRouter } from "@tanstack/react-router";
71
+import { useNavigate, useRouter } from "@tanstack/react-router";
72
import {
73
MAX_SIDEBAR_THREAD_PREVIEW_COUNT,
74
MIN_SIDEBAR_THREAD_PREVIEW_COUNT,
@@ -129,11 +129,7 @@ import { useThreadActions } from "../hooks/useThreadActions";
129
import { projectEnvironment } from "../state/projects";
130
import { threadEnvironment, useEnvironmentThread } from "../state/threads";
131
import { useEnvironment, useEnvironments, usePrimaryEnvironmentId } from "../state/environments";
132
-import {
133
- buildThreadRouteParams,
134
- resolveActiveThreadRouteRef,
135
- resolveThreadRouteTarget,
136
-} from "../threadRoutes";
132
+import { buildThreadRouteParams, resolveActiveThreadRouteRef } from "../threadRoutes";
133
import { stackedThreadToast, toastManager } from "./ui/toast";
134
import { formatRelativeTimeLabel } from "../timestampFormat";
135
import { Kbd } from "./ui/kbd";
@@ -225,6 +221,7 @@ import {
221
type SidebarProjectSnapshot,
222
} from "../sidebarProjectGrouping";
223
import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
224
+import { useThreadRouteTarget } from "../hooks/useThreadRouteTarget";
225
const SIDEBAR_SORT_LABELS: Record<SidebarProjectSortOrder, string> = {
226
updated_at: "Last user message",
227
created_at: "Created at",
@@ -3253,10 +3250,7 @@ export default function LegacySidebar() {
3250
const handleNewThread = useNewThreadHandler();
3251
const { archiveThread, deleteThread, markThreadUnread } = useThreadActions();
3252
const { isMobile, setOpenMobile } = useSidebar();
3256
- const routeTarget = useParams({
3257
- strict: false,
3258
- select: (params) => resolveThreadRouteTarget(params),
3259
- });
3253
+ const routeTarget = useThreadRouteTarget();
3254
const routeDraftThread = useComposerDraftStore((store) =>
3255
routeTarget?.kind === "draft" ? store.getDraftSession(routeTarget.draftId) : null,
3256
);
apps/web/src/components/Sidebar.tsx
+4
-10
@@ -97,7 +97,7 @@ import {
97
type PointerEvent as ReactPointerEvent,
98
type ReactNode,
99
} from "react";
100
-import { useParams, useRouter } from "@tanstack/react-router";
100
+import { useRouter } from "@tanstack/react-router";
101
102
import { useRightPanelStore } from "../rightPanelStore";
103
import {
@@ -166,11 +166,7 @@ import { useEnvironmentQuery } from "../state/query";
166
import { useThreadSearch } from "../state/queries";
167
import { useOrchestrationCommand } from "../state/use-orchestration-command";
168
import { readEnvironmentScope, useEnvironmentScope } from "../state/session";
169
-import {
170
- buildThreadRouteParams,
171
- resolveActiveThreadRouteRef,
172
- resolveThreadRouteTarget,
173
-} from "../threadRoutes";
169
+import { buildThreadRouteParams, resolveActiveThreadRouteRef } from "../threadRoutes";
170
import { formatRelativeTimeLabel, parseTimestampDate } from "../timestampFormat";
171
import type { SidebarThreadSummary } from "../types";
172
import { isScratchProject } from "@t3tools/client-runtime/state/projects";
@@ -286,6 +282,7 @@ import {
282
type ComposerThreadDraftState,
283
type DraftSessionState,
284
} from "../composerDraftStore";
285
+import { useThreadRouteTarget } from "../hooks/useThreadRouteTarget";
286
287
const EMPTY_PROVIDER_ENTRIES: ReadonlyMap<string, ProviderInstanceEntry> = new Map();
288
// Collapsed shelves share one empty list so a route change alone does not
@@ -2680,10 +2677,7 @@ export default function Sidebar() {
2677
const toggleThreadSelection = useThreadSelectionStore((s) => s.toggleThread);
2678
const rangeSelectTo = useThreadSelectionStore((s) => s.rangeSelectTo);
2679
const acknowledgeWoke = useAcknowledgeThreadWoke();
2683
- const routeTarget = useParams({
2684
- strict: false,
2685
- select: (params) => resolveThreadRouteTarget(params),
2686
- });
2680
+ const routeTarget = useThreadRouteTarget();
2681
const routeDraftThread = useComposerDraftStore((store) =>
2682
routeTarget?.kind === "draft" ? store.getDraftSession(routeTarget.draftId) : null,
2683
);
apps/web/src/components/ui/toast.tsx
+2
-6
@@ -11,7 +11,6 @@ import {
11
type KeyboardEvent,
12
type ReactNode,
13
} from "react";
14
-import { useParams } from "@tanstack/react-router";
14
import { type ScopedThreadRef, type ThreadId } from "@t3tools/contracts";
15
import { CircleAlertIcon, CircleCheckIcon, InfoIcon, TriangleAlertIcon, XIcon } from "lucide-react";
16
import { Check, ChevronDown, ChevronUp, Copy } from "lucide";
@@ -21,7 +20,6 @@ import { Button, buttonVariants } from "~/components/ui/button";
20
import { MorphIcon } from "~/components/MorphIcon";
21
import { useComposerDraftStore } from "~/composerDraftStore";
22
import { useCopyToClipboard } from "~/hooks/useCopyToClipboard";
24
-import { resolveThreadRouteTarget } from "~/threadRoutes";
23
import {
24
buildVisibleToastLayout,
25
hasVisibleToastAction,
@@ -29,6 +27,7 @@ import {
27
shouldRenderThreadScopedToast,
28
} from "./toast.logic";
29
import { Tooltip, TooltipPopup, TooltipTrigger } from "./tooltip";
30
+import { useThreadRouteTarget } from "~/hooks/useThreadRouteTarget";
31
32
export type ThreadToastData = {
33
threadRef?: ScopedThreadRef | null;
@@ -411,10 +410,7 @@ interface ToastProviderProps extends Toast.Provider.Props {
410
}
411
412
function useActiveThreadRefFromRoute(): ScopedThreadRef | null {
414
- const routeTarget = useParams({
415
- strict: false,
416
- select: (params) => resolveThreadRouteTarget(params),
417
- });
413
+ const routeTarget = useThreadRouteTarget();
414
const activeDraftSession = useComposerDraftStore((store) =>
415
routeTarget?.kind === "draft" ? store.getDraftSession(routeTarget.draftId) : null,
416
);
apps/web/src/hooks/useHandleNewThread.ts
+3
-5
@@ -4,7 +4,7 @@ import {
4
scopeThreadRef,
5
} from "@t3tools/client-runtime/environment";
6
import { DEFAULT_SERVER_SETTINGS, type ScopedProjectRef, type ThreadId } from "@t3tools/contracts";
7
-import { useParams, useRouter } from "@tanstack/react-router";
7
+import { useRouter } from "@tanstack/react-router";
8
import {
9
composerDraftHasUserContent,
10
markPromotedDraftThreadByRef,
@@ -40,6 +40,7 @@ import { environmentServerConfigsAtom } from "../state/server";
40
import { resolveThreadRouteTarget } from "../threadRoutes";
41
import { legacyProjectCwdPreferenceKey, useUiStateStore } from "../uiStateStore";
42
import { useClientSettings } from "./useSettings";
43
+import { useThreadRouteTarget } from "./useThreadRouteTarget";
44
45
interface NewThreadWorkspaceOptions {
46
branch?: string | null;
@@ -384,10 +385,7 @@ export function useNewThreadHandler() {
385
386
export function useHandleNewThread() {
387
const projectOrder = useUiStateStore((store) => store.projectOrder);
387
- const routeTarget = useParams({
388
- strict: false,
389
- select: (params) => resolveThreadRouteTarget(params),
390
- });
388
+ const routeTarget = useThreadRouteTarget();
389
const routeThreadRef = routeTarget?.kind === "server" ? routeTarget.threadRef : null;
390
const routeDraftId = routeTarget?.kind === "draft" ? routeTarget.draftId : null;
391
const activeThread = useThreadShell(routeThreadRef);
apps/web/src/hooks/useThreadRouteTarget.ts
new
+27
@@ -0,0 +1,27 @@
1
+import type { ScopedThreadRef } from "@t3tools/contracts";
2
+import { useParams } from "@tanstack/react-router";
3
+
4
+import {
5
+ resolveThreadRouteRef,
6
+ resolveThreadRouteTarget,
7
+ type ThreadRouteTarget,
8
+} from "../threadRoutes";
9
+
10
+// The router re-runs selectors on every store update (preloads, location state,
11
+// same-route navigations) and compares with ===. Selecting the string params keeps
12
+// those updates from reaching consumers; the target is then built once per id change.
13
+function useThreadRouteIds() {
14
+ const environmentId = useParams({ strict: false, select: (params) => params.environmentId });
15
+ const threadId = useParams({ strict: false, select: (params) => params.threadId });
16
+ return { environmentId, threadId };
17
+}
18
+
19
+export function useThreadRouteTarget(): ThreadRouteTarget | null {
20
+ const { environmentId, threadId } = useThreadRouteIds();
21
+ const draftId = useParams({ strict: false, select: (params) => params.draftId });
22
+ return resolveThreadRouteTarget({ environmentId, threadId, draftId });
23
+}
24
+
25
+export function useThreadRouteRef(): ScopedThreadRef | null {
26
+ return resolveThreadRouteRef(useThreadRouteIds());
27
+}
apps/web/src/routes/_chat.tsx
+3
-6
@@ -1,12 +1,11 @@
1
import { AuthPreviewOperateScope } from "@t3tools/contracts";
2
-import { Outlet, createFileRoute, redirect, useParams } from "@tanstack/react-router";
2
+import { Outlet, createFileRoute, redirect } from "@tanstack/react-router";
3
import { useAtomValue } from "@effect/atom-react";
4
import { useEffect } from "react";
5
6
import { isCommandPaletteOpen } from "../commandPaletteBus";
7
import { ThreadRouteView } from "../components/ThreadRouteView";
8
import { ThreadLinkPrompt } from "../components/promptLinks/ThreadLinkPrompt";
9
-import { resolveThreadRouteTarget } from "../threadRoutes";
9
import { useClientSettings, useLegacySidebarEnabled } from "../hooks/useSettings";
10
import { openCommandPalette } from "../commandPaletteBus";
11
import { useProjects } from "../state/entities";
@@ -30,6 +29,7 @@ import { selectActiveRightPanel, useRightPanelStore } from "../rightPanelStore";
29
import { useThreadSelectionStore } from "../threadSelectionStore";
30
import { stackedThreadToast, toastManager } from "~/components/ui/toast";
31
import { primaryServerKeybindingsAtom } from "~/state/server";
32
+import { useThreadRouteTarget } from "../hooks/useThreadRouteTarget";
33
34
function ChatRouteGlobalShortcuts() {
35
const clearSelection = useThreadSelectionStore((state) => state.clearSelection);
@@ -208,10 +208,7 @@ function ChatRouteGlobalShortcuts() {
208
function ChatRouteLayout() {
209
// Both thread routes render here, not in their own leaf components, so the
210
// draft-to-thread promotion keeps one ChatView mounted across the swap.
211
- const threadTarget = useParams({
212
- strict: false,
213
- select: (params) => resolveThreadRouteTarget(params),
214
- });
211
+ const threadTarget = useThreadRouteTarget();
212
return (
213
<>
214
<ChatRouteGlobalShortcuts />