Skip to content

Commit aa3dd09

Browse files
tyler-daneclaude
andcommitted
fix(web): preserve sidebar width across views and refreshes
Drags on zoomed/HiDPI displays persist fractional widths (clientX is fractional), and readSidebarWidth's Number.isInteger guard rejected them, silently resetting the sidebar to the default width on every panel mount (view switch or refresh). Round on write so stored widths stay canonical, and accept any finite stored value on read (round + clamp) so already-persisted fractional values heal instead of resetting. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 90f30f2 commit aa3dd09

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

packages/web/src/components/PlannerSidebar/storage/sidebar-width.storage.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,24 @@ describe("sidebar width storage", () => {
3535
expect(readSidebarWidth()).toBe(SIDEBAR_MAX_WIDTH);
3636
});
3737

38+
it("rounds fractional stored widths instead of resetting to the default", () => {
39+
// Drags on zoomed/HiDPI displays used to persist values like "400.5",
40+
// which the old integer-only guard rejected — resetting the sidebar on
41+
// every view switch and refresh.
42+
localStorage.setItem(STORAGE_KEYS.SIDEBAR_WIDTH, "400.5");
43+
44+
expect(readSidebarWidth()).toBe(401);
45+
});
46+
3847
it("writes widths through the storage abstraction", () => {
3948
writeSidebarWidth(360);
4049

4150
expect(localStorage.getItem(STORAGE_KEYS.SIDEBAR_WIDTH)).toBe("360");
4251
});
52+
53+
it("rounds fractional widths on write", () => {
54+
writeSidebarWidth(400.5);
55+
56+
expect(localStorage.getItem(STORAGE_KEYS.SIDEBAR_WIDTH)).toBe("401");
57+
});
4358
});

packages/web/src/components/PlannerSidebar/storage/sidebar-width.storage.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@ export function readSidebarWidth(): number {
99
const stored = persistentBrowserStore.get(STORAGE_KEYS.SIDEBAR_WIDTH);
1010
if (stored === null) return SIDEBAR_DEFAULT_WIDTH;
1111

12+
// Drags on zoomed/HiDPI displays produce fractional widths, so tolerate
13+
// (and heal) any finite stored value instead of resetting to the default.
1214
const width = Number(stored);
13-
return Number.isInteger(width)
14-
? clampSidebarWidth(width)
15+
return Number.isFinite(width)
16+
? clampSidebarWidth(Math.round(width))
1517
: SIDEBAR_DEFAULT_WIDTH;
1618
}
1719

1820
export function writeSidebarWidth(width: number): void {
19-
persistentBrowserStore.set(STORAGE_KEYS.SIDEBAR_WIDTH, String(width));
21+
persistentBrowserStore.set(
22+
STORAGE_KEYS.SIDEBAR_WIDTH,
23+
String(Math.round(width)),
24+
);
2025
}

0 commit comments

Comments
 (0)