Skip to content

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.

Extract stripDiffSearchParams helper to deduplicate diff param stripping logic

Cursor Agent842e327583f2
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx
index fd94dfff9..4a374b6d6 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 (
<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>
diff --git a/apps/web/src/components/DiffPanel.tsx b/apps/web/src/components/DiffPanel.tsx
index 6510cea7e..33149c508 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 1b1ccded2..fd3d6cae7 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<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 } : {}),
};
}
-
diff --git a/apps/web/src/routes/_chat.$threadId.tsx b/apps/web/src/routes/_chat.$threadId.tsx
index ecf1e2bd5..8bb8aa389 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,
});
-