Skip to content

Commit af5c62c

Browse files
levochkaaclaude
andcommitted
feat(web): add a setting to share the right panel width across threads
The right panel remembers its width per thread. With Settings → Appearance → Shared panel width on, ChatView passes no per-thread key, so the resize hook uses its app-wide key and a resize in one thread applies to every thread. Off by default; per-thread widths stay stored and return when it is turned off. The resize hook now reads its width through useLocalStorage, so panels that share a key follow resizes from other tabs, and keeps a width storage rejected for the rest of the session. Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 71dfe27 commit af5c62c

9 files changed

Lines changed: 109 additions & 29 deletions

File tree

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3955,7 +3955,10 @@ export default function ChatView(props: ChatViewProps) {
39553955
<ChatRightPanel
39563956
sheet={shouldUsePlanSidebarSheet}
39573957
workspaceLayoutElement={workspaceLayoutElement}
3958-
widthStorageKey={`t3code:preview-panel-width:${activeThreadKey}`}
3958+
// `undefined` selects the hook's single app-wide key.
3959+
widthStorageKey={
3960+
settings.sharedPanelWidth ? undefined : `t3code:preview-panel-width:${activeThreadKey}`
3961+
}
39593962
sheetAnimationDurationMs={panelAnimationsActive ? panelAnimationDurationMs : 0}
39603963
onCloseSheet={closePreviewPanelStable}
39613964
open={rightPanelOpen}

‎apps/web/src/components/chat/ChatRightPanel.tsx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ import { usePreviewPanelInlineSize } from "../../hooks/usePreviewPanelInlineSize
22
import { RightPanelSheet } from "../RightPanelSheet";
33
import { RightPanelTabs, type RightPanelTabsProps } from "../RightPanelTabs";
44

5-
type ChatRightPanelProps = Omit<RightPanelTabsProps, "mode" | "inlineSize" | "maximized"> & {
5+
type ChatRightPanelProps = Omit<
6+
RightPanelTabsProps,
7+
"mode" | "inlineSize" | "maximized" | "widthStorageKey"
8+
> & {
69
readonly sheet: boolean;
710
readonly maximized: boolean;
811
readonly workspaceLayoutElement: HTMLElement | null;
9-
readonly widthStorageKey: string;
12+
readonly widthStorageKey: string | undefined;
1013
readonly sheetAnimationDurationMs: number;
1114
readonly onCloseSheet: () => void;
1215
};

‎apps/web/src/components/settings/AppearanceSettingsPanel.tsx‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,28 @@ export function AppearanceSettingsPanel() {
257257
}
258258
/>
259259

260+
<SettingsRow
261+
{...searchableSetting("shared-panel-width")}
262+
description="Use one right panel width in every thread. When off, each thread keeps its own width."
263+
resetAction={
264+
settings.sharedPanelWidth !== DEFAULT_UNIFIED_SETTINGS.sharedPanelWidth ? (
265+
<SettingResetButton
266+
label="shared panel width"
267+
onClick={() =>
268+
updateSettings({ sharedPanelWidth: DEFAULT_UNIFIED_SETTINGS.sharedPanelWidth })
269+
}
270+
/>
271+
) : null
272+
}
273+
control={
274+
<Switch
275+
checked={settings.sharedPanelWidth}
276+
onCheckedChange={(checked) => updateSettings({ sharedPanelWidth: Boolean(checked) })}
277+
aria-label="Use the same right panel width in every thread"
278+
/>
279+
}
280+
/>
281+
260282
<SettingsRow
261283
{...searchableSetting("chat-width")}
262284
description="Set how wide messages and the composer can grow on large screens."

‎apps/web/src/components/settings/SettingsPanels.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,9 @@ export function useSettingsRestore(onRestored?: () => void) {
514514
DEFAULT_UNIFIED_SETTINGS.persistComposerContextStrip
515515
? ["Composer context"]
516516
: []),
517+
...(settings.sharedPanelWidth !== DEFAULT_UNIFIED_SETTINGS.sharedPanelWidth
518+
? ["Shared panel width"]
519+
: []),
517520
...getChangedTypographySettingLabels(settings),
518521
...(settings.diffFilesCollapsed !== DEFAULT_UNIFIED_SETTINGS.diffFilesCollapsed
519522
? ["Default diff file state"]
@@ -648,6 +651,7 @@ export function useSettingsRestore(onRestored?: () => void) {
648651
inAppNotificationsEnabled: DEFAULT_UNIFIED_SETTINGS.inAppNotificationsEnabled,
649652
wordWrap: DEFAULT_UNIFIED_SETTINGS.wordWrap,
650653
persistComposerContextStrip: DEFAULT_UNIFIED_SETTINGS.persistComposerContextStrip,
654+
sharedPanelWidth: DEFAULT_UNIFIED_SETTINGS.sharedPanelWidth,
651655
diffFilesCollapsed: DEFAULT_UNIFIED_SETTINGS.diffFilesCollapsed,
652656
diffIgnoreWhitespace: DEFAULT_UNIFIED_SETTINGS.diffIgnoreWhitespace,
653657
diffLayout: DEFAULT_UNIFIED_SETTINGS.diffLayout,

‎apps/web/src/components/settings/settingsSearch.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,12 @@ export const SETTINGS_SEARCH_ITEMS = [
427427
title: "Composer context",
428428
to: "/settings/appearance",
429429
},
430+
{
431+
id: "shared-panel-width",
432+
title: "Shared panel width",
433+
to: "/settings/appearance",
434+
searchTerms: ["right side panel diff changes browser resize size every all threads"],
435+
},
430436
{
431437
id: "project-grouping",
432438
title: msg("Project grouping"),

‎apps/web/src/hooks/useLocalStorage.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export function writeLocalStorageValue<T, E>(
157157
value: T | ((val: T) => T),
158158
initialValue: T,
159159
schema: Schema.Codec<T, E>,
160-
): void {
160+
): boolean {
161161
try {
162162
let valueToStore: T;
163163
if (typeof value === "function") {
@@ -186,8 +186,10 @@ export function writeLocalStorageValue<T, E>(
186186
setLocalStorageItem(key, valueToStore, schema);
187187
}
188188
dispatchLocalStorageChange(key);
189+
return true;
189190
} catch (error) {
190191
console.error("[LOCALSTORAGE] Could not update stored value.", error);
192+
return false;
191193
}
192194
}
193195

‎apps/web/src/hooks/useResizableWidth.browser.test.tsx‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ function Panel({ defaultWidth }: { defaultWidth: number }) {
2121
);
2222
}
2323

24+
function dragLeftBy(handle: Element, distance: number) {
25+
const init = { bubbles: true, button: 0, pointerId: 1 };
26+
handle.dispatchEvent(new PointerEvent("pointerdown", { ...init, clientX: 500 }));
27+
handle.dispatchEvent(new PointerEvent("pointermove", { ...init, clientX: 500 - distance }));
28+
handle.dispatchEvent(new PointerEvent("pointerup", { ...init, clientX: 500 - distance }));
29+
}
30+
2431
describe("useResizableWidth", () => {
2532
it("follows a responsive default until the user saves a width", async () => {
2633
const previous = localStorage.getItem(STORAGE_KEY);
@@ -82,4 +89,42 @@ describe("useResizableWidth", () => {
8289
else localStorage.setItem(STORAGE_KEY, previous);
8390
}
8491
});
92+
93+
it("follows a width another tab stores under the same key", async () => {
94+
using _storage = { [Symbol.dispose]: () => localStorage.removeItem(STORAGE_KEY) };
95+
// This hook only needs browser storage and React; no navigation is involved.
96+
await using screen = await render(<Panel defaultWidth={400} />, { router: false });
97+
await expect.element(screen.getByText("400")).toBeInTheDocument();
98+
99+
// Another tab's write reaches this one only as a storage event.
100+
await act(() => {
101+
localStorage.setItem(STORAGE_KEY, "500");
102+
window.dispatchEvent(new StorageEvent("storage", { key: STORAGE_KEY }));
103+
});
104+
await expect.element(screen.getByText("500")).toBeInTheDocument();
105+
});
106+
107+
it("keeps a width storage rejected for the next drag and a new default", async () => {
108+
using _storage = { [Symbol.dispose]: () => localStorage.removeItem(STORAGE_KEY) };
109+
// This hook only needs browser storage and React; no navigation is involved.
110+
await using screen = await render(<Panel defaultWidth={400} />, { router: false });
111+
// Synthetic pointer ids are not active pointers, so the browser would reject capture.
112+
using _capture = vi
113+
.spyOn(HTMLElement.prototype, "setPointerCapture")
114+
.mockImplementation(() => {});
115+
using _write = vi.spyOn(Storage.prototype, "setItem").mockImplementation(() => {
116+
throw new DOMException("Storage is full.", "QuotaExceededError");
117+
});
118+
using _log = vi.spyOn(console, "error").mockImplementation(() => {});
119+
const handle = screen.getByRole("separator").element();
120+
121+
await act(() => dragLeftBy(handle, 100));
122+
await expect.element(screen.getByText("500")).toBeInTheDocument();
123+
124+
await act(() => dragLeftBy(handle, 50));
125+
await expect.element(screen.getByText("550")).toBeInTheDocument();
126+
127+
await screen.rerender(<Panel defaultWidth={200} />);
128+
await expect.element(screen.getByText("550")).toBeInTheDocument();
129+
});
85130
});

‎apps/web/src/hooks/useResizableWidth.ts‎

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import * as Schema from "effect/Schema";
22
import { type PointerEvent as ReactPointerEvent, useLayoutEffect, useState } from "react";
33

4-
import { getLocalStorageItem, setLocalStorageItem } from "./useLocalStorage";
4+
import { useLocalStorage, writeLocalStorageValue } from "./useLocalStorage";
55
import { useResizeDrag } from "./useResizeDrag";
66
import { useStableCallback } from "./useStableCallback";
77

8-
const WidthSchema = Schema.Finite;
8+
// Null while no width is saved, so an unsaved width survives a responsive default changing.
9+
const StoredWidthSchema = Schema.NullOr(Schema.Finite);
910

1011
/** The host must size itself from this custom property. */
1112
export const RESIZABLE_WIDTH_PROPERTY = "--resizable-width";
@@ -40,34 +41,26 @@ export function useResizableWidth(options: UseResizableWidthOptions): {
4041
return Math.max(minWidth, Math.min(maxWidth, value));
4142
};
4243

43-
const readWidth = (): number | null => {
44-
if (typeof window === "undefined") return null;
45-
try {
46-
const stored = getLocalStorageItem(storageKey, WidthSchema);
47-
return stored === null ? null : clamp(stored);
48-
} catch (error) {
49-
console.error("Could not read persisted panel width.", error);
50-
return null;
51-
}
52-
};
53-
const [widthState, setWidthState] = useState(() => ({ storageKey, width: readWidth() }));
54-
if (widthState.storageKey !== storageKey) {
55-
setWidthState({ storageKey, width: readWidth() });
56-
}
57-
58-
const clampedWidth = clamp(widthState.width ?? defaultWidth);
44+
// Panels that share a key follow each other's drags, in this tab and in others.
45+
const [storedWidth] = useLocalStorage(storageKey, null, StoredWidthSchema);
46+
// Resizing remains usable for this session when browser storage is unavailable.
47+
const [unsaved, setUnsaved] = useState<{
48+
readonly storageKey: string;
49+
readonly storedWidth: number | null;
50+
readonly width: number;
51+
} | null>(null);
52+
const clampedWidth = clamp(
53+
unsaved?.storageKey === storageKey && unsaved.storedWidth === storedWidth
54+
? unsaved.width
55+
: (storedWidth ?? defaultWidth),
56+
);
5957
const restoreWidth = useStableCallback((host: HTMLElement | null) => {
6058
host?.style.setProperty(RESIZABLE_WIDTH_PROPERTY, `${clampedWidth}px`);
6159
});
6260

6361
const commitWidth = (nextStorageKey: string, nextWidth: number) => {
64-
// Resizing remains usable for this session when browser storage is unavailable.
65-
setWidthState({ storageKey: nextStorageKey, width: nextWidth });
66-
try {
67-
setLocalStorageItem(nextStorageKey, nextWidth, WidthSchema);
68-
} catch (error) {
69-
console.error("Could not persist panel width.", error);
70-
}
62+
const saved = writeLocalStorageValue(nextStorageKey, nextWidth, null, StoredWidthSchema);
63+
setUnsaved(saved ? null : { storageKey: nextStorageKey, storedWidth, width: nextWidth });
7164
};
7265

7366
const drag = useResizeDrag<HTMLElement>((event) => {

‎packages/contracts/src/settings.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ export const ClientSettingsSchema = Schema.Struct({
499499
persistComposerContextStrip: Schema.Boolean.pipe(
500500
Schema.withDecodingDefault(Effect.succeed(false)),
501501
),
502+
sharedPanelWidth: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
502503

503504
favorites: ModelFavorites.pipe(Schema.withDecodingDefault(Effect.succeed([]))),
504505
providerModelPreferences: ProviderModelPreferences.pipe(
@@ -2039,6 +2040,7 @@ export const ClientSettingsPatch = Schema.Struct({
20392040
fontFamilyTerminal: Schema.optionalKey(FontFamilyPreference),
20402041
fontSmoothing: Schema.optionalKey(Schema.Boolean),
20412042
persistComposerContextStrip: Schema.optionalKey(Schema.Boolean),
2043+
sharedPanelWidth: Schema.optionalKey(Schema.Boolean),
20422044
favorites: Schema.optionalKey(ModelFavorites),
20432045
providerModelPreferences: Schema.optionalKey(ProviderModelPreferences),
20442046
pullRequestMergeMethodOverrides: Schema.optionalKey(

0 commit comments

Comments
 (0)