@devries-cameron20 / t3code-1 / commits / 8f6c9b7144
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): preserve typed dimensions with the aspect ratio locked (#23338)

Co-authored-by: GPT-6.1 Sol <noreply@openai.com>

Victor Vogel committed Oct 30, 2026 at 15:45 UTC 8f6c9b71444c56a3454e2eb40899672dc509e9da
2 files changed +96 -9
apps/web/src/browser/BrowserDeviceToolbar.browser.test.tsx new
+71
@@ -0,0 +1,71 @@
1 +import type { PreviewViewportSetting } from "@t3tools/contracts";
2 +import { useState } from "react";
3 +import { expect, it } from "vite-plus/test";
4 +import { userEvent } from "vite-plus/test/browser";
5 +
6 +import { render } from "../../test/render";
7 +import { BrowserDeviceToolbar } from "./BrowserDeviceToolbar";
8 +
9 +function Viewport({ width = 1920, height = 1080 }: { width?: number; height?: number }) {
10 + const [setting, setSetting] = useState<PreviewViewportSetting>({
11 + _tag: "freeform",
12 + width,
13 + height,
14 + });
15 + const [aspectRatio, setAspectRatio] = useState<number | null>(width / height);
16 + if (setting._tag === "fill") throw new Error("Expected fixed viewport");
17 + return (
18 + <>
19 + <BrowserDeviceToolbar
20 + setting={setting}
21 + width={800}
22 + aspectRatio={aspectRatio}
23 + onAspectRatioChange={setAspectRatio}
24 + onChange={async (next) => setSetting(next)}
25 + />
26 + <output aria-label="Saved viewport">
27 + {setting.width} × {setting.height}
28 + </output>
29 + <button type="button">Leave toolbar</button>
30 + </>
31 + );
32 +}
33 +
34 +it.each([
35 + { width: 1920, height: 1080, axis: "width", typed: "2560", expected: "2560 × 1440" },
36 + { width: 390, height: 844, axis: "height", typed: "2532", expected: "1170 × 2532" },
37 +])("keeps each typed $axis digit until the locked size is committed", async (testCase) => {
38 + await using screen = await render(<Viewport {...testCase} />);
39 + const input = screen.getByRole("spinbutton", { name: `Viewport ${testCase.axis}` });
40 + await userEvent.clear(input);
41 + await userEvent.type(input, testCase.typed);
42 + await expect.element(input).toHaveValue(Number(testCase.typed));
43 + await screen.getByRole("button", { name: "Leave toolbar" }).click();
44 + await expect
45 + .element(screen.getByRole("status", { name: "Saved viewport" }))
46 + .toHaveTextContent(testCase.expected);
47 +});
48 +
49 +it("clamps a completed width below the locked minimum when leaving the toolbar", async () => {
50 + await using screen = await render(<Viewport />);
51 + const input = screen.getByRole("spinbutton", { name: "Viewport width" });
52 + await userEvent.clear(input);
53 + await userEvent.type(input, "256");
54 + await expect.element(input).toHaveValue(256);
55 + await screen.getByRole("button", { name: "Leave toolbar" }).click();
56 + await expect
57 + .element(screen.getByRole("status", { name: "Saved viewport" }))
58 + .toHaveTextContent("427 × 240");
59 +});
60 +
61 +it("still limits a completed locked size to the viewport area cap", async () => {
62 + await using screen = await render(<Viewport width={1920} height={1920} />);
63 + const input = screen.getByRole("spinbutton", { name: "Viewport width" });
64 + await userEvent.clear(input);
65 + await userEvent.type(input, "3840");
66 + await expect.element(input).toHaveValue(3840);
67 + await screen.getByRole("button", { name: "Leave toolbar" }).click();
68 + await expect
69 + .element(screen.getByRole("status", { name: "Saved viewport" }))
70 + .toHaveTextContent("2880 × 2880");
71 +});
apps/web/src/browser/BrowserDeviceToolbar.tsx
+25 -9
@@ -51,6 +51,7 @@ export function BrowserDeviceToolbar({
51 const [customSize, setCustomSize] = useState<{
52 readonly width: string;
53 readonly height: string;
54 + readonly axis?: "width" | "height";
55 } | null>(null);
56 const presentedSize = customSize ?? {
57 width: String(setting.width),
@@ -61,15 +62,25 @@ export function BrowserDeviceToolbar({
62 PREVIEW_VIEWPORT_PRESETS.some((preset) => preset.id === setting.presetId)
63 ? setting.presetId
64 : RESPONSIVE_VALUE;
64 - const customWidth = Number(presentedSize.width);
65 - const customHeight = Number(presentedSize.height);
65 + const typedWidth = Number(presentedSize.width);
66 + const typedHeight = Number(presentedSize.height);
67 + const { width: customWidth, height: customHeight } =
68 + aspectRatio === null || customSize?.axis === undefined
69 + ? { width: typedWidth, height: typedHeight }
70 + : resizeFreeformViewport(
71 + { width: typedWidth, height: typedHeight },
72 + { x: 0, y: 0 },
73 + 1,
74 + customSize?.axis === "height" ? "south" : "east",
75 + aspectRatio,
76 + );
77 const customValid =
67 - Number.isInteger(customWidth) &&
68 - Number.isInteger(customHeight) &&
69 - customWidth >= PREVIEW_VIEWPORT_MIN_DIMENSION &&
70 - customWidth <= PREVIEW_VIEWPORT_MAX_DIMENSION &&
71 - customHeight >= PREVIEW_VIEWPORT_MIN_DIMENSION &&
72 - customHeight <= PREVIEW_VIEWPORT_MAX_DIMENSION &&
78 + Number.isInteger(typedWidth) &&
79 + Number.isInteger(typedHeight) &&
80 + typedWidth >= PREVIEW_VIEWPORT_MIN_DIMENSION &&
81 + typedWidth <= PREVIEW_VIEWPORT_MAX_DIMENSION &&
82 + typedHeight >= PREVIEW_VIEWPORT_MIN_DIMENSION &&
83 + typedHeight <= PREVIEW_VIEWPORT_MAX_DIMENSION &&
84 customWidth * customHeight <= PREVIEW_VIEWPORT_MAX_AREA;
85
86 const apply = (next: PreviewViewportSetting, nextAspectRatio = aspectRatio) => {
@@ -96,6 +107,7 @@ export function BrowserDeviceToolbar({
107 const next = {
108 width: axis === "width" ? value : (current?.width ?? String(setting.width)),
109 height: axis === "height" ? value : (current?.height ?? String(setting.height)),
110 + axis,
111 };
112 const numeric = Number(value);
113 if (
@@ -115,7 +127,11 @@ export function BrowserDeviceToolbar({
127 axis === "width" ? "east" : "south",
128 aspectRatio,
129 );
118 - return { width: String(resized.width), height: String(resized.height) };
130 + return {
131 + ...next,
132 + width: axis === "width" ? value : String(resized.width),
133 + height: axis === "height" ? value : String(resized.height),
134 + };
135 });
136 };
137