From 842e327583f214714abbde82e7e19a6341c3d140 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 19 Feb 2026 23:36:12 +0000 Subject: [PATCH] Extract stripDiffSearchParams helper to deduplicate diff param stripping logic Consolidate the repeated pattern of destructuring and removing diff/diffTurnId/diffFilePath search params into a single stripDiffSearchParams() function in diffRouteSearch.ts. Replaces 5 identical destructuring blocks across 3 files with calls to the shared helper. Applied via @cursor push command --- apps/web/src/components/ChatView.tsx | 40 +++++++++++++------------ apps/web/src/components/DiffPanel.tsx | 24 ++++----------- apps/web/src/diffRouteSearch.ts | 8 ++++- apps/web/src/routes/_chat.$threadId.tsx | 11 ++----- 4 files changed, 35 insertions(+), 48 deletions(-) diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index fd94dfff9385b0eff8c2c86ae54da7d7845bfcd8..4a374b6d67f08521cda82cdd6a053e1dca5e5a01 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -36,7 +36,7 @@ import { projectSearchEntriesQueryOptions } from "~/lib/projectReactQuery"; import { serverConfigQueryOptions, serverQueryKeys } from "~/lib/serverReactQuery"; import { isElectron } from "../env"; -import { parseDiffRouteSearch } from "../diffRouteSearch"; +import { parseDiffRouteSearch, stripDiffSearchParams } from "../diffRouteSearch"; import { buildBootstrapInput } from "../historyBootstrap"; import { type ComposerTriggerKind, @@ -1967,12 +1967,7 @@ export default function ChatView({ threadId }: ChatViewProps) { to: "/$threadId", params: { threadId }, search: (previous) => { - const { - diff: _diff, - diffTurnId: _diffTurnId, - diffFilePath: _diffFilePath, - ...rest - } = previous; + const rest = stripDiffSearchParams(previous); return diffOpen ? rest : { ...rest, diff: "1" }; }, }); @@ -1983,12 +1978,7 @@ export default function ChatView({ threadId }: ChatViewProps) { to: "/$threadId", params: { threadId }, search: (previous) => { - const { - diff: _diff, - diffTurnId: _diffTurnId, - diffFilePath: _diffFilePath, - ...rest - } = previous; + const rest = stripDiffSearchParams(previous); return filePath ? { ...rest, diff: "1", diffTurnId: turnId, diffFilePath: filePath } : { ...rest, diff: "1", diffTurnId: turnId }; @@ -2828,11 +2818,16 @@ const MessagesTimeline = memo(function MessagesTimeline({ row.message.id, ); if (!turnSummary) return null; - const checkpointFilesState = turnCheckpointFilesByTurnId.get(turnSummary.turnId); + const checkpointFilesState = turnCheckpointFilesByTurnId.get( + turnSummary.turnId, + ); const checkpointFiles = checkpointFilesState?.files ?? []; const summaryStat = checkpointFiles.reduce( (acc, file) => { - if (typeof file.additions !== "number" || typeof file.deletions !== "number") { + if ( + typeof file.additions !== "number" || + typeof file.deletions !== "number" + ) { return acc; } return { @@ -2843,7 +2838,9 @@ const MessagesTimeline = memo(function MessagesTimeline({ { additions: 0, deletions: 0 }, ); const changedFileCountLabel = - checkpointFilesState?.status === "ready" ? String(checkpointFiles.length) : "..."; + checkpointFilesState?.status === "ready" + ? String(checkpointFiles.length) + : "..."; return (
@@ -2854,7 +2851,9 @@ const MessagesTimeline = memo(function MessagesTimeline({ • +{summaryStat.additions} / - -{summaryStat.deletions} + + -{summaryStat.deletions} + )}

@@ -2862,12 +2861,15 @@ const MessagesTimeline = memo(function MessagesTimeline({ type="button" size="xs" variant="outline" - onClick={() => onOpenTurnDiff(turnSummary.turnId, checkpointFiles[0]?.path)} + onClick={() => + onOpenTurnDiff(turnSummary.turnId, checkpointFiles[0]?.path) + } > View diff
- {!checkpointFilesState || checkpointFilesState.status === "pending" ? ( + {!checkpointFilesState || + checkpointFilesState.status === "pending" ? (

Waiting for checkpoint metadata...

diff --git a/apps/web/src/components/DiffPanel.tsx b/apps/web/src/components/DiffPanel.tsx index 6510cea7ee3ca999660b8447c360dde862b7f352..33149c5088a7f5082a821512302c953f4295a4a1 100644 --- a/apps/web/src/components/DiffPanel.tsx +++ b/apps/web/src/components/DiffPanel.tsx @@ -1,16 +1,12 @@ import { parsePatchFiles } from "@pierre/diffs"; -import { - FileDiff, - type FileDiffMetadata, - Virtualizer, -} from "@pierre/diffs/react"; +import { FileDiff, type FileDiffMetadata, Virtualizer } from "@pierre/diffs/react"; import { useQuery } from "@tanstack/react-query"; import { useNavigate, useParams, useSearch } from "@tanstack/react-router"; import { Columns2Icon, Rows3Icon } from "lucide-react"; import { useEffect, useMemo, useRef, useState } from "react"; import { checkpointDiffQueryOptions } from "~/lib/providerReactQuery"; import { cn } from "~/lib/utils"; -import { parseDiffRouteSearch } from "../diffRouteSearch"; +import { parseDiffRouteSearch, stripDiffSearchParams } from "../diffRouteSearch"; import { isElectron } from "../env"; import { useNativeApi } from "../hooks/useNativeApi"; import { useTheme } from "../hooks/useTheme"; @@ -101,7 +97,7 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) { useTurnDiffSummaries(activeThread); const selectedTurnId = diffSearch.diffTurnId ?? null; - const selectedFilePath = selectedTurnId !== null ? diffSearch.diffFilePath ?? null : null; + const selectedFilePath = selectedTurnId !== null ? (diffSearch.diffFilePath ?? null) : null; const selectedTurn = selectedTurnId === null ? undefined @@ -205,12 +201,7 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) { to: "/$threadId", params: { threadId: activeThread.id }, search: (previous) => { - const { - diff: _diff, - diffTurnId: _diffTurnId, - diffFilePath: _diffFilePath, - ...rest - } = previous; + const rest = stripDiffSearchParams(previous); return { ...rest, diff: "1", diffTurnId: turnId }; }, }); @@ -221,12 +212,7 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) { to: "/$threadId", params: { threadId: activeThread.id }, search: (previous) => { - const { - diff: _diff, - diffTurnId: _diffTurnId, - diffFilePath: _diffFilePath, - ...rest - } = previous; + const rest = stripDiffSearchParams(previous); return { ...rest, diff: "1" }; }, }); diff --git a/apps/web/src/diffRouteSearch.ts b/apps/web/src/diffRouteSearch.ts index 1b1ccded2427f9a07e213f16554b91b7c2d45cf1..fd3d6cae7087bb84286b5dfa75009a330c4541cd 100644 --- a/apps/web/src/diffRouteSearch.ts +++ b/apps/web/src/diffRouteSearch.ts @@ -12,6 +12,13 @@ function normalizeSearchString(value: unknown): string | undefined { return normalized.length > 0 ? normalized : undefined; } +export function stripDiffSearchParams>( + params: T, +): Omit { + const { diff: _diff, diffTurnId: _diffTurnId, diffFilePath: _diffFilePath, ...rest } = params; + return rest as Omit; +} + export function parseDiffRouteSearch(search: Record): DiffRouteSearch { const diff = search.diff === "1" ? "1" : undefined; const diffTurnId = diff ? normalizeSearchString(search.diffTurnId) : undefined; @@ -23,4 +30,3 @@ export function parseDiffRouteSearch(search: Record): DiffRoute ...(diffFilePath ? { diffFilePath } : {}), }; } - diff --git a/apps/web/src/routes/_chat.$threadId.tsx b/apps/web/src/routes/_chat.$threadId.tsx index ecf1e2bd53bf39931d872c404a5440387d4a2c38..8bb8aa389cfdcc7483ce6286eb1c28a335a4cfd0 100644 --- a/apps/web/src/routes/_chat.$threadId.tsx +++ b/apps/web/src/routes/_chat.$threadId.tsx @@ -2,7 +2,7 @@ import { createFileRoute, useNavigate } from "@tanstack/react-router"; import { Activity, Suspense, lazy, type ReactNode, useCallback, useEffect } from "react"; import ChatView from "../components/ChatView"; -import { parseDiffRouteSearch } from "../diffRouteSearch"; +import { parseDiffRouteSearch, stripDiffSearchParams } from "../diffRouteSearch"; import { useMediaQuery } from "../hooks/useMediaQuery"; import { useStore } from "../store"; import { Sheet, SheetPopup } from "../components/ui/sheet"; @@ -58,13 +58,7 @@ function ChatThreadRouteView() { to: "/$threadId", params: { threadId }, search: (previous) => { - const { - diff: _diff, - diffTurnId: _diffTurnId, - diffFilePath: _diffFilePath, - ...rest - } = previous; - return rest; + return stripDiffSearchParams(previous); }, }); }, [navigate, threadId]); @@ -118,4 +112,3 @@ export const Route = createFileRoute("/_chat/$threadId")({ validateSearch: (search) => parseDiffRouteSearch(search), component: ChatThreadRouteView, }); - -- 2.54.0