Compare commits

...
Author SHA1 Message Date
Cursor Agent f87f01fb81 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.
2026-02-19 18:27:46 +00:00
4 changed files with 35 additions and 48 deletions

No files matched your search

+21 -19
View File
@@ -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 (
<div className="mt-2 rounded-lg border border-border/80 bg-card/45 p-2.5">
<div className="mb-1.5 flex items-center justify-between gap-2">
@@ -2854,7 +2851,9 @@ const MessagesTimeline = memo(function MessagesTimeline({
<span className="mx-1">•</span>
<span className="text-success">+{summaryStat.additions}</span>
<span className="mx-0.5 text-muted-foreground/70">/</span>
<span className="text-destructive">-{summaryStat.deletions}</span>
<span className="text-destructive">
-{summaryStat.deletions}
</span>
</>
)}
</p>
@@ -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
</Button>
</div>
{!checkpointFilesState || checkpointFilesState.status === "pending" ? (
{!checkpointFilesState ||
checkpointFilesState.status === "pending" ? (
<p className="text-[11px] text-muted-foreground/70">
Waiting for checkpoint metadata...
</p>
+5 -19
View File
@@ -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" };
},
});
+7 -1
View File
@@ -12,6 +12,13 @@ function normalizeSearchString(value: unknown): string | undefined {
return normalized.length > 0 ? normalized : undefined;
}
export function stripDiffSearchParams<T extends Record<string, unknown>>(
params: T,
): Omit<T, "diff" | "diffTurnId" | "diffFilePath"> {
const { diff: _diff, diffTurnId: _diffTurnId, diffFilePath: _diffFilePath, ...rest } = params;
return rest as Omit<T, "diff" | "diffTurnId" | "diffFilePath">;
}
export function parseDiffRouteSearch(search: Record<string, unknown>): DiffRouteSearch {
const diff = search.diff === "1" ? "1" : undefined;
const diffTurnId = diff ? normalizeSearchString(search.diffTurnId) : undefined;
@@ -23,4 +30,3 @@ export function parseDiffRouteSearch(search: Record<string, unknown>): DiffRoute
...(diffFilePath ? { diffFilePath } : {}),
};
}
+2 -9
View File
@@ -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,
});