Skip to content

Commit b5d9f85

Browse files
authored
fix(web): keep inward mini browser resizes from growing (#26027)
1 parent d14074f commit b5d9f85

2 files changed

Lines changed: 56 additions & 6 deletions

File tree

‎apps/web/src/components/chat/chatCanvasLayout.test.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,47 @@ const expectClear = (result: ReturnType<typeof resolve>) => {
2323
};
2424

2525
describe("chat canvas layout", () => {
26+
it("does not enlarge the preview when its right edge is dragged inward", () => {
27+
for (const height of [300, 400, 600, 900]) {
28+
for (const x of [12, 200, 500, 700]) {
29+
const start = resolve(1000, { ...preview, position: { x, y: 500 } }, height).frame!;
30+
const resized = resizePreviewMiniPlayer({
31+
start,
32+
direction: "east",
33+
delta: { x: -30, y: 0 },
34+
source: preview.source,
35+
container: { width: 1000, height },
36+
});
37+
expect(resized.width, JSON.stringify({ height, x, start, resized })).toBeLessThanOrEqual(
38+
start.width,
39+
);
40+
const rendered = resolve(
41+
1000,
42+
{
43+
...preview,
44+
width: resized.width,
45+
position: resized,
46+
lastInteraction: "resize",
47+
},
48+
height,
49+
).frame!;
50+
expect(
51+
rendered.width,
52+
JSON.stringify({ height, x, start, resized, rendered }),
53+
).toBeLessThanOrEqual(start.width);
54+
expect(rendered.x).toBe(start.x);
55+
expect(rendered.y, JSON.stringify({ height, x, start, resized, rendered })).toBe(start.y);
56+
expect(
57+
resolve(1000, {
58+
...preview,
59+
width: resized.width,
60+
position: resized,
61+
lastInteraction: "resize",
62+
}).frame!.width,
63+
).toBe(resized.width);
64+
}
65+
}
66+
});
2667
it("lifts a growing preview above the composer without snapping at the chat boundary", () => {
2768
let previous: ReturnType<typeof resolve> | undefined;
2869
for (let width = 480; width <= 1100; width++) {

‎apps/web/src/components/preview/previewMiniPlayerLayout.ts‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,21 @@ const availableArea = (
107107
PREVIEW_MINI_PLAYER_EDGE_GAP * 2,
108108
});
109109

110+
const minimumPreviewMiniPlayerWidth = (source: PreviewMiniPlayerSize) =>
111+
Math.max(
112+
PREVIEW_MINI_PLAYER_MIN_SIZE.width,
113+
(PREVIEW_MINI_PLAYER_MIN_SIZE.height * source.width) / source.height,
114+
);
115+
110116
function fitPreviewMiniPlayerWidth(
111117
desiredWidth: number,
112118
source: PreviewMiniPlayerSize,
113119
max: PreviewMiniPlayerSize,
120+
minimumWidth = minimumPreviewMiniPlayerWidth(source),
114121
): PreviewMiniPlayerSize {
115122
const aspectRatio = source.width / source.height;
116123
const width = Math.min(
117-
Math.max(
118-
desiredWidth,
119-
PREVIEW_MINI_PLAYER_MIN_SIZE.width,
120-
PREVIEW_MINI_PLAYER_MIN_SIZE.height * aspectRatio,
121-
),
124+
Math.max(desiredWidth, minimumWidth),
122125
Math.max(1, max.width),
123126
Math.max(1, max.height * aspectRatio),
124127
);
@@ -244,6 +247,7 @@ export function resolvePreviewMiniPlayerFrame(input: {
244247
position && width ? { composer: obstacles.composer, detailsCard: null } : obstacles,
245248
position && width ? spanOf(position.x, width) : null,
246249
),
250+
width ?? undefined,
247251
);
248252
const { detailsCard } = obstacles;
249253
const anchored =
@@ -307,7 +311,12 @@ export function resizePreviewMiniPlayer(input: {
307311
: horizontal
308312
? desiredWidth
309313
: desiredHeight * aspectRatio;
310-
const size = fitPreviewMiniPlayerWidth(desired, source, max);
314+
const size = fitPreviewMiniPlayerWidth(
315+
desired,
316+
source,
317+
max,
318+
Math.min(start.width, minimumPreviewMiniPlayerWidth(source)),
319+
);
311320
const position = clampPreviewMiniPlayerPosition(
312321
{ x: west ? right - size.width : start.x, y: north ? bottom - size.height : start.y },
313322
container,

0 commit comments

Comments
 (0)