History

fix(web): persist diff view mode (#5731)

Leonel Rivas committed 3 months agov0.0.33-nightly.20260808.1038

Commit 89ee6921 parent a20923c3 files · +36 −3Browse files

Unified · Split

3 files
  1. apps/web/src/components/DiffPanel.tsx +2 −2
  2. apps/web/src/diffPanelStore.test.ts +27 −1
  3. apps/web/src/diffPanelStore.ts +7 −0
apps/web/src/components/DiffPanel.tsx+2−2
@@ -76,7 +76,6 @@ import { reviewEnvironment } from "../state/review"; · 75 unmodified lines
7676 import { vcsEnvironment } from "../state/vcs";
7777 import { buildBaseRefChoices, filterBaseRefChoices } from "../lib/baseRefChoices";
7878
79−type DiffRenderMode = "stacked" | "split";
8079 type DiffThemeType = "light" | "dark";
8180 const AUTOMATIC_BASE_REF = "__automatic_base_ref__";
8281
@@ -312,7 +311,8 @@ export default function DiffPanel({ · 229 unmodified lines
312311 const { resolvedTheme } = useTheme();
313312 const settings = useClientSettings();
314313 const [initialGitScope] = useState(initialGitScopeProp);
315− const [diffRenderMode, setDiffRenderMode] = useState<DiffRenderMode>("stacked");
314+ const diffRenderMode = useDiffPanelStore((state) => state.diffRenderMode);
315+ const setDiffRenderMode = useDiffPanelStore((state) => state.setDiffRenderMode);
316316 const [wordWrap, setWordWrap] = useState(settings.wordWrap);
317317 const [diffIgnoreWhitespace, setDiffIgnoreWhitespace] = useState(settings.diffIgnoreWhitespace);
318318 const [baseRefQuery, setBaseRefQuery] = useState("");
apps/web/src/diffPanelStore.test.ts+27−1
@@ -7,7 +7,33 @@ import { selectThreadDiffPanelSelection, useDiffPanelStore } from "./diffPanelSt · 6 unmodified lines
77 const THREAD_REF = scopeThreadRef(EnvironmentId.make("environment-1"), ThreadId.make("thread-1"));
88
99 describe("diffPanelStore", () => {
10− beforeEach(() => useDiffPanelStore.setState({ byThreadKey: {}, branchBaseRefByThreadKey: {} }));
10+ beforeEach(() =>
11+ useDiffPanelStore.setState({
12+ byThreadKey: {},
13+ branchBaseRefByThreadKey: {},
14+ diffRenderMode: "stacked",
15+ }),
16+ );
17+
18+ it("keeps the selected render mode in panel and persisted state", async () => {
19+ useDiffPanelStore.getState().setDiffRenderMode("split");
20+
21+ expect(useDiffPanelStore.getState().diffRenderMode).toBe("split");
22+ expect(
23+ useDiffPanelStore.persist.getOptions().partialize?.(useDiffPanelStore.getState()),
24+ ).toMatchObject({ diffRenderMode: "split" });
25+
26+ const { name, storage } = useDiffPanelStore.persist.getOptions();
27+ if (!name) throw new Error("Expected diff panel persistence to have a storage name");
28+ const persisted = await storage?.getItem(name);
29+ expect(persisted?.state).toMatchObject({ diffRenderMode: "split" });
30+
31+ useDiffPanelStore.setState({ diffRenderMode: "stacked" });
32+ if (persisted) await storage?.setItem(name, persisted);
33+ await useDiffPanelStore.persist.rehydrate();
34+
35+ expect(useDiffPanelStore.getState().diffRenderMode).toBe("split");
36+ });
1137
1238 it("defaults each thread to branch changes when the working tree is clean", () => {
1339 expect(
apps/web/src/diffPanelStore.ts+7−0
@@ -10,12 +10,16 @@ export type DiffPanelSelection = · 9 unmodified lines
1010 | { kind: "unstaged" }
1111 | { kind: "turn"; turnId: TurnId; filePath: string | null; revealRequestId: number };
1212
13+export type DiffRenderMode = "stacked" | "split";
14+
1315 const DEFAULT_SELECTION: DiffPanelSelection = { kind: "branch", baseRef: null };
1416 const DEFAULT_WORKING_TREE_SELECTION: DiffPanelSelection = { kind: "unstaged" };
1517
1618 interface DiffPanelStoreState {
1719 byThreadKey: Record<string, DiffPanelSelection>;
1820 branchBaseRefByThreadKey: Record<string, string | null>;
21+ diffRenderMode: DiffRenderMode;
22+ setDiffRenderMode: (mode: DiffRenderMode) => void;
1923 selectGitScope: (ref: ScopedThreadRef, scope: "branch" | "unstaged") => void;
2024 selectBranchBaseRef: (ref: ScopedThreadRef, baseRef: string | null) => void;
2125 selectTurn: (ref: ScopedThreadRef, turnId: TurnId, filePath?: string) => void;
@@ -33,6 +37,8 @@ export const useDiffPanelStore = create<DiffPanelStoreState>()( · 11 unmodified lines
3337 (set) => ({
3438 byThreadKey: {},
3539 branchBaseRefByThreadKey: {},
40+ diffRenderMode: "stacked",
41+ setDiffRenderMode: (diffRenderMode) => set({ diffRenderMode }),
3642 selectGitScope: (ref, scope) =>
3743 set((state) => {
3844 const threadKey = scopedThreadKey(ref);
@@ -126,6 +132,7 @@ export const useDiffPanelStore = create<DiffPanelStoreState>()( · 87 unmodified lines
126132 partialize: (state) => ({
127133 byThreadKey: state.byThreadKey,
128134 branchBaseRefByThreadKey: state.branchBaseRefByThreadKey,
135+ diffRenderMode: state.diffRenderMode,
129136 }),
130137 },
131138 ),

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t