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.
fix(web): persist diff view mode (#5731)
Leonel Rivas89ee692bf043
diff --git a/apps/web/src/components/DiffPanel.tsx b/apps/web/src/components/DiffPanel.tsxindex 76191e6d4..a62f5edd4 100644--- a/apps/web/src/components/DiffPanel.tsx+++ b/apps/web/src/components/DiffPanel.tsx@@ -76,7 +76,6 @@ import { reviewEnvironment } from "../state/review";import { vcsEnvironment } from "../state/vcs";import { buildBaseRefChoices, filterBaseRefChoices } from "../lib/baseRefChoices";-type DiffRenderMode = "stacked" | "split";type DiffThemeType = "light" | "dark";const AUTOMATIC_BASE_REF = "__automatic_base_ref__";@@ -312,7 +311,8 @@ export default function DiffPanel({const { resolvedTheme } = useTheme();const settings = useClientSettings();const [initialGitScope] = useState(initialGitScopeProp);- const [diffRenderMode, setDiffRenderMode] = useState<DiffRenderMode>("stacked");+ const diffRenderMode = useDiffPanelStore((state) => state.diffRenderMode);+ const setDiffRenderMode = useDiffPanelStore((state) => state.setDiffRenderMode);const [wordWrap, setWordWrap] = useState(settings.wordWrap);const [diffIgnoreWhitespace, setDiffIgnoreWhitespace] = useState(settings.diffIgnoreWhitespace);const [baseRefQuery, setBaseRefQuery] = useState("");diff --git a/apps/web/src/diffPanelStore.test.ts b/apps/web/src/diffPanelStore.test.tsindex 607b7c8d5..7e7c95921 100644--- a/apps/web/src/diffPanelStore.test.ts+++ b/apps/web/src/diffPanelStore.test.ts@@ -7,7 +7,33 @@ import { selectThreadDiffPanelSelection, useDiffPanelStore } from "./diffPanelStconst THREAD_REF = scopeThreadRef(EnvironmentId.make("environment-1"), ThreadId.make("thread-1"));describe("diffPanelStore", () => {- beforeEach(() => useDiffPanelStore.setState({ byThreadKey: {}, branchBaseRefByThreadKey: {} }));+ beforeEach(() =>+ useDiffPanelStore.setState({+ byThreadKey: {},+ branchBaseRefByThreadKey: {},+ diffRenderMode: "stacked",+ }),+ );++ it("keeps the selected render mode in panel and persisted state", async () => {+ useDiffPanelStore.getState().setDiffRenderMode("split");++ expect(useDiffPanelStore.getState().diffRenderMode).toBe("split");+ expect(+ useDiffPanelStore.persist.getOptions().partialize?.(useDiffPanelStore.getState()),+ ).toMatchObject({ diffRenderMode: "split" });++ const { name, storage } = useDiffPanelStore.persist.getOptions();+ if (!name) throw new Error("Expected diff panel persistence to have a storage name");+ const persisted = await storage?.getItem(name);+ expect(persisted?.state).toMatchObject({ diffRenderMode: "split" });++ useDiffPanelStore.setState({ diffRenderMode: "stacked" });+ if (persisted) await storage?.setItem(name, persisted);+ await useDiffPanelStore.persist.rehydrate();++ expect(useDiffPanelStore.getState().diffRenderMode).toBe("split");+ });it("defaults each thread to branch changes when the working tree is clean", () => {expect(diff --git a/apps/web/src/diffPanelStore.ts b/apps/web/src/diffPanelStore.tsindex 56b5ad23f..ebb560a23 100644--- a/apps/web/src/diffPanelStore.ts+++ b/apps/web/src/diffPanelStore.ts@@ -10,12 +10,16 @@ export type DiffPanelSelection =| { kind: "unstaged" }| { kind: "turn"; turnId: TurnId; filePath: string | null; revealRequestId: number };+export type DiffRenderMode = "stacked" | "split";+const DEFAULT_SELECTION: DiffPanelSelection = { kind: "branch", baseRef: null };const DEFAULT_WORKING_TREE_SELECTION: DiffPanelSelection = { kind: "unstaged" };interface DiffPanelStoreState {byThreadKey: Record<string, DiffPanelSelection>;branchBaseRefByThreadKey: Record<string, string | null>;+ diffRenderMode: DiffRenderMode;+ setDiffRenderMode: (mode: DiffRenderMode) => void;selectGitScope: (ref: ScopedThreadRef, scope: "branch" | "unstaged") => void;selectBranchBaseRef: (ref: ScopedThreadRef, baseRef: string | null) => void;selectTurn: (ref: ScopedThreadRef, turnId: TurnId, filePath?: string) => void;@@ -33,6 +37,8 @@ export const useDiffPanelStore = create<DiffPanelStoreState>()((set) => ({byThreadKey: {},branchBaseRefByThreadKey: {},+ diffRenderMode: "stacked",+ setDiffRenderMode: (diffRenderMode) => set({ diffRenderMode }),selectGitScope: (ref, scope) =>set((state) => {const threadKey = scopedThreadKey(ref);@@ -126,6 +132,7 @@ export const useDiffPanelStore = create<DiffPanelStoreState>()(partialize: (state) => ({byThreadKey: state.byThreadKey,branchBaseRefByThreadKey: state.branchBaseRefByThreadKey,+ diffRenderMode: state.diffRenderMode,}),},),