Skip to content
TypeScript

fix(web): keep inward mini browser resizes from growing (#26027)

diddletimeb5d9f85b9adc
diff --git a/apps/web/src/components/chat/chatCanvasLayout.test.ts b/apps/web/src/components/chat/chatCanvasLayout.test.ts
index 0a62861eacb..748d8abb5d1 100644
--- a/apps/web/src/components/chat/chatCanvasLayout.test.ts
+++ b/apps/web/src/components/chat/chatCanvasLayout.test.ts
@@ -23,6 +23,47 @@ const expectClear = (result: ReturnType<typeof resolve>) => {
};
describe("chat canvas layout", () => {
+ it("does not enlarge the preview when its right edge is dragged inward", () => {
+ for (const height of [300, 400, 600, 900]) {
+ for (const x of [12, 200, 500, 700]) {
+ const start = resolve(1000, { ...preview, position: { x, y: 500 } }, height).frame!;
+ const resized = resizePreviewMiniPlayer({
+ start,
+ direction: "east",
+ delta: { x: -30, y: 0 },
+ source: preview.source,
+ container: { width: 1000, height },
+ });
+ expect(resized.width, JSON.stringify({ height, x, start, resized })).toBeLessThanOrEqual(
+ start.width,
+ );
+ const rendered = resolve(
+ 1000,
+ {
+ ...preview,
+ width: resized.width,
+ position: resized,
+ lastInteraction: "resize",
+ },
+ height,
+ ).frame!;
+ expect(
+ rendered.width,
+ JSON.stringify({ height, x, start, resized, rendered }),
+ ).toBeLessThanOrEqual(start.width);
+ expect(rendered.x).toBe(start.x);
+ expect(rendered.y, JSON.stringify({ height, x, start, resized, rendered })).toBe(start.y);
+ expect(
+ resolve(1000, {
+ ...preview,
+ width: resized.width,
+ position: resized,
+ lastInteraction: "resize",
+ }).frame!.width,
+ ).toBe(resized.width);
+ }
+ }
+ });
it("lifts a growing preview above the composer without snapping at the chat boundary", () => {
let previous: ReturnType<typeof resolve> | undefined;
for (let width = 480; width <= 1100; width++) {
diff --git a/apps/web/src/components/preview/previewMiniPlayerLayout.ts b/apps/web/src/components/preview/previewMiniPlayerLayout.ts
index 0d75a1311fb..f66183c9fcb 100644
--- a/apps/web/src/components/preview/previewMiniPlayerLayout.ts
+++ b/apps/web/src/components/preview/previewMiniPlayerLayout.ts
@@ -107,18 +107,21 @@ const availableArea = (
PREVIEW_MINI_PLAYER_EDGE_GAP * 2,
});
+const minimumPreviewMiniPlayerWidth = (source: PreviewMiniPlayerSize) =>
+ Math.max(
+ PREVIEW_MINI_PLAYER_MIN_SIZE.width,
+ (PREVIEW_MINI_PLAYER_MIN_SIZE.height * source.width) / source.height,
+ );
+
function fitPreviewMiniPlayerWidth(
desiredWidth: number,
source: PreviewMiniPlayerSize,
max: PreviewMiniPlayerSize,
+ minimumWidth = minimumPreviewMiniPlayerWidth(source),
): PreviewMiniPlayerSize {
const aspectRatio = source.width / source.height;
const width = Math.min(
- Math.max(
- desiredWidth,
- PREVIEW_MINI_PLAYER_MIN_SIZE.width,
- PREVIEW_MINI_PLAYER_MIN_SIZE.height * aspectRatio,
- ),
+ Math.max(desiredWidth, minimumWidth),
Math.max(1, max.width),
Math.max(1, max.height * aspectRatio),
);
@@ -244,6 +247,7 @@ export function resolvePreviewMiniPlayerFrame(input: {
position && width ? { composer: obstacles.composer, detailsCard: null } : obstacles,
position && width ? spanOf(position.x, width) : null,
),
+ width ?? undefined,
);
const { detailsCard } = obstacles;
const anchored =
@@ -307,7 +311,12 @@ export function resizePreviewMiniPlayer(input: {
: horizontal
? desiredWidth
: desiredHeight * aspectRatio;
- const size = fitPreviewMiniPlayerWidth(desired, source, max);
+ const size = fitPreviewMiniPlayerWidth(
+ desired,
+ source,
+ max,
+ Math.min(start.width, minimumPreviewMiniPlayerWidth(source)),
+ );
const position = clampPreviewMiniPlayerPosition(
{ x: west ? right - size.width : start.x, y: north ? bottom - size.height : start.y },
container,