Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ import { projectSearchEntriesQueryOptions } from "~/lib/projectReactQuery";
import { serverConfigQueryOptions, serverQueryKeys } from "~/lib/serverReactQuery";

import { isElectron } from "../env";
import { parseDiffRouteSearch, stripDiffSearchParams } from "../diffRouteSearch";
import {
clearDiffSearchParams,
parseDiffRouteSearch,
stripDiffSearchParams,
} from "../diffRouteSearch";
import {
type ComposerSlashCommand,
type ComposerTrigger,
Expand Down Expand Up @@ -1400,7 +1404,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
replace: true,
search: (previous) => {
const rest = stripDiffSearchParams(previous);
return diffOpen ? rest : { ...rest, diff: "1" };
return diffOpen ? clearDiffSearchParams(previous) : { ...rest, diff: "1" };
},
});
}, [diffOpen, navigate, threadId]);
Expand Down
43 changes: 42 additions & 1 deletion apps/web/src/diffRouteSearch.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { describe, expect, it } from "vitest";

import { parseDiffRouteSearch } from "./diffRouteSearch";
import {
clearDiffSearchParams,
parseDiffRouteSearch,
stripDiffSearchParams,
} from "./diffRouteSearch";

describe("parseDiffRouteSearch", () => {
it("parses valid diff search values", () => {
Expand Down Expand Up @@ -72,3 +76,40 @@ describe("parseDiffRouteSearch", () => {
});
});
});

describe("stripDiffSearchParams", () => {
it("removes diff search keys", () => {
const stripped = stripDiffSearchParams({
diff: "1",
diffFilePath: "src/app.ts",
diffTurnId: "turn-1",
project: "demo",
});

expect(stripped).toEqual({ project: "demo" });
expect("diff" in stripped).toBe(false);
expect("diffTurnId" in stripped).toBe(false);
expect("diffFilePath" in stripped).toBe(false);
});
});

describe("clearDiffSearchParams", () => {
it("keeps explicit undefined tombstones for diff keys", () => {
const cleared = clearDiffSearchParams({
diff: "1",
diffFilePath: "src/app.ts",
diffTurnId: "turn-1",
project: "demo",
});

expect(cleared).toEqual({
diff: undefined,
diffFilePath: undefined,
diffTurnId: undefined,
project: "demo",
});
expect("diff" in cleared).toBe(true);
expect("diffTurnId" in cleared).toBe(true);
expect("diffFilePath" in cleared).toBe(true);
});
});
22 changes: 19 additions & 3 deletions apps/web/src/diffRouteSearch.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { TurnId } from "@t3tools/contracts";

export interface DiffRouteSearch {
diff?: "1";
diffTurnId?: TurnId;
diffFilePath?: string;
diff?: "1" | undefined;
diffTurnId?: TurnId | undefined;
diffFilePath?: string | undefined;
}

function isDiffOpenValue(value: unknown): boolean {
Expand All @@ -25,6 +25,22 @@ export function stripDiffSearchParams<T extends Record<string, unknown>>(
return rest as Omit<T, "diff" | "diffTurnId" | "diffFilePath">;
}

export function clearDiffSearchParams<T extends Record<string, unknown>>(
params: T,
): Omit<T, "diff" | "diffTurnId" | "diffFilePath"> & {
diff: undefined;
diffTurnId: undefined;
diffFilePath: undefined;
} {
const rest = stripDiffSearchParams(params);
return {
...rest,
diff: undefined,
diffTurnId: undefined,
diffFilePath: undefined,
};
}

export function parseDiffRouteSearch(search: Record<string, unknown>): DiffRouteSearch {
const diff = isDiffOpenValue(search.diff) ? "1" : undefined;
const diffTurnIdRaw = diff ? normalizeSearchString(search.diffTurnId) : undefined;
Expand Down
12 changes: 10 additions & 2 deletions apps/web/src/routes/_chat.$threadId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Suspense, lazy, type ReactNode, useCallback, useEffect } from "react";
import ChatView from "../components/ChatView";
import { useComposerDraftStore } from "../composerDraftStore";
import {
clearDiffSearchParams,
type DiffRouteSearch,
parseDiffRouteSearch,
stripDiffSearchParams,
Expand Down Expand Up @@ -133,10 +134,17 @@ const DiffPanelInlineSidebar = (props: {
className="w-auto min-h-0 flex-none bg-transparent"
style={{ "--sidebar-width": DIFF_INLINE_DEFAULT_WIDTH } as React.CSSProperties}
>
{diffOpen ? (
<div
aria-hidden="true"
className="fixed inset-0 z-[15] bg-transparent"
onClick={onCloseDiff}
/>
) : null}
<Sidebar
side="right"
collapsible="offcanvas"
className="border-l border-border bg-card text-foreground"
className="z-20 border-l border-border bg-card text-foreground"
resizable={{
minWidth: DIFF_INLINE_SIDEBAR_MIN_WIDTH,
shouldAcceptWidth: shouldAcceptInlineSidebarWidth,
Expand Down Expand Up @@ -171,7 +179,7 @@ function ChatThreadRouteView() {
to: "/$threadId",
params: { threadId },
search: (previous) => {
return stripDiffSearchParams(previous);
return clearDiffSearchParams(previous);
},
});
}, [navigate, threadId]);
Expand Down
Loading