Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Fix Images and Video header controls clipping in narrow windows (#15798)

Lee Jacksond697fefbb66a
diff --git a/studio/frontend/src/components/media-rail-resize-handle.tsx b/studio/frontend/src/components/media-rail-resize-handle.tsx
index 94869b37ead..1664f1bb6f4 100644
--- a/studio/frontend/src/components/media-rail-resize-handle.tsx
+++ b/studio/frontend/src/components/media-rail-resize-handle.tsx
@@ -12,10 +12,10 @@ import {
} from "@/hooks/use-media-rail-width";
import { cn } from "@/lib/utils";
-/** The rail's rendered width, mirroring the pages' `min(rail, 100% - 13rem)`. */
+/** The rail's rendered width, leaving the same preview minimum as its page. */
const RAIL_BOX_WIDTH: Record<MediaRailKind, string> = {
- images: "min(var(--media-rail-width,calc(408px*var(--ui-space-scale,1))),calc(100% - 13rem))",
- video: "min(var(--media-rail-width,calc(400px*var(--ui-space-scale,1))),calc(100% - 13rem))",
+ images: "min(var(--media-rail-width,calc(408px*var(--ui-space-scale,1))),calc(100% - var(--media-header-min-width,13rem)))",
+ video: "min(var(--media-rail-width,calc(408px*var(--ui-space-scale,1))),calc(100% - var(--media-header-min-width,13rem)))",
audio: "min(var(--media-rail-width,calc(408px*var(--ui-space-scale,1))),calc(100% - 13rem))",
};
@@ -33,7 +33,7 @@ export function MediaRailResizeHandle({
const anchorRef = useRef<HTMLSpanElement>(null);
const root = () =>
anchorRef.current?.closest<HTMLElement>(`[${MEDIA_RAIL_ROOT_ATTR}]`) ?? null;
- // The `100% - 13rem` cap in layout px, so drags and keys start from the width actually shown.
+ // Match the page cap in layout px, so drags and keys start from the width actually shown.
const [cap, setCap] = useState<number | null>(null);
useLayoutEffect(() => {
const anchor = anchorRef.current;
@@ -47,13 +47,19 @@ export function MediaRailResizeHandle({
? block.clientWidth
: block.clientWidth - parseFloat(style.paddingLeft) - parseFloat(style.paddingRight);
const rem = parseFloat(getComputedStyle(document.documentElement).fontSize) || 16;
- setCap((inner - 13 * rem) / rail.scale);
+ // A present 0px header inset wins over the window-control fallback, as in the CSS var().
+ const rightInset = parseFloat(
+ style.getPropertyValue("--studio-chat-header-right-inset").trim() ||
+ style.getPropertyValue("--studio-window-control-inset").trim(),
+ ) || 0;
+ const previewMinimum = kind === "audio" ? 13 * rem : 14 * rem * rail.scale + rightInset;
+ setCap((inner - previewMinimum) / rail.scale);
};
update();
const observer = new ResizeObserver(update);
observer.observe(block);
return () => observer.disconnect();
- }, [placement, rail.scale]);
+ }, [kind, placement, rail.scale]);
// The cap can fall below the stored minimum (high interface scale near the breakpoint).
const max = cap === null ? rail.max : Math.max(0, Math.min(rail.max, cap));
const width = Math.min(rail.width, max);
diff --git a/studio/frontend/src/features/images/images-page.tsx b/studio/frontend/src/features/images/images-page.tsx
index 59c3ba54ada..85664c63e98 100644
--- a/studio/frontend/src/features/images/images-page.tsx
+++ b/studio/frontend/src/features/images/images-page.tsx
@@ -5885,12 +5885,12 @@ export function ImagesPage({
<div
{...{ [MEDIA_RAIL_ROOT_ATTR]: "" }}
style={railRootStyle}
- className="diffusion-surface @container relative flex h-full min-h-0 min-w-0 flex-1 flex-col overflow-hidden pt-[var(--studio-content-top-inset,0px)]"
+ className="diffusion-surface media-header-layout @container relative flex h-full min-h-0 min-w-0 flex-1 flex-col overflow-hidden pt-[var(--studio-content-top-inset,0px)]"
>
<MediaRailResizeHandle kind="images" placement="page" className="hidden @[50rem]:block" />
{/* Portals to body, and this page stays mounted off-route, so gate it like the composer. */}
{active && <GuidedTour {...tour.tourProps} />}
- <div className="pointer-events-none relative z-40 grid h-[calc(48px*var(--ui-space-scale,1))] shrink-0 grid-cols-[minmax(0,var(--media-rail-width,calc(408px*var(--ui-space-scale,1))))_minmax(13rem,1fr)] @max-[30rem]:grid-cols-[minmax(0,1fr)_auto]">
+ <div className="pointer-events-none relative z-40 grid h-[calc(48px*var(--ui-space-scale,1))] shrink-0 grid-cols-[minmax(0,var(--media-rail-width,calc(408px*var(--ui-space-scale,1))))_minmax(var(--media-header-min-width),1fr)] @max-[30rem]:grid-cols-[minmax(0,1fr)_auto]">
<div
className={cn(
"pointer-events-none flex h-full min-w-0 items-start overflow-hidden pr-3 @[50rem]:border-r @[50rem]:border-border/60",
@@ -6004,7 +6004,7 @@ export function ImagesPage({
<div className="flex min-h-0 w-full min-w-0 flex-1 flex-col overflow-y-auto overflow-x-hidden @[50rem]:flex-row @[50rem]:overflow-hidden">
<div
data-tour="images-settings"
- className="flex w-full shrink-0 flex-col border-b border-border/60 @[50rem]:w-[min(var(--media-rail-width,calc(408px*var(--ui-space-scale,1))),calc(100%-13rem))] @[50rem]:overflow-hidden @[50rem]:border-r @[50rem]:border-b-0"
+ className="flex w-full shrink-0 flex-col border-b border-border/60 @[50rem]:w-[min(var(--media-rail-width,calc(408px*var(--ui-space-scale,1))),calc(100%-var(--media-header-min-width)))] @[50rem]:overflow-hidden @[50rem]:border-r @[50rem]:border-b-0"
>
<div
ref={attachSettingsScroll}
diff --git a/studio/frontend/src/features/images/train/diffusion-train-panel.tsx b/studio/frontend/src/features/images/train/diffusion-train-panel.tsx
index f48cc557e36..b837c258e47 100644
--- a/studio/frontend/src/features/images/train/diffusion-train-panel.tsx
+++ b/studio/frontend/src/features/images/train/diffusion-train-panel.tsx
@@ -1636,7 +1636,7 @@ export function DiffusionTrainPanel({
// row pan the page sideways on a phone.
return (
<div className="flex min-h-0 w-full min-w-0 flex-1 flex-col overflow-y-auto overflow-x-hidden pr-5 sm:pr-8 @[50rem]:flex-row @[50rem]:overflow-hidden">
- <div className="flex w-full min-w-0 shrink-0 flex-col border-b border-border/60 pl-10 max-sm:pl-5 @[50rem]:w-[min(var(--media-rail-width,calc(408px*var(--ui-space-scale,1))),calc(100%-13rem+--spacing(8)))] @[50rem]:overflow-hidden @[50rem]:border-r @[50rem]:border-b-0">
+ <div className="flex w-full min-w-0 shrink-0 flex-col border-b border-border/60 pl-10 max-sm:pl-5 @[50rem]:w-[min(var(--media-rail-width,calc(408px*var(--ui-space-scale,1))),calc(100%-var(--media-header-min-width,13rem)+--spacing(8)))] @[50rem]:overflow-hidden @[50rem]:border-r @[50rem]:border-b-0">
<div
ref={attachSettingsScroll}
onScroll={onSettingsScroll}
diff --git a/studio/frontend/src/features/video/video-page.tsx b/studio/frontend/src/features/video/video-page.tsx
index caa9fbf4280..5242539c9f6 100644
--- a/studio/frontend/src/features/video/video-page.tsx
+++ b/studio/frontend/src/features/video/video-page.tsx
@@ -3688,7 +3688,7 @@ function VideoGenerator({
<div
{...{ [MEDIA_RAIL_ROOT_ATTR]: "" }}
style={railRootStyle}
- className="diffusion-surface @container relative flex h-full min-h-0 min-w-0 flex-1 flex-col overflow-hidden pt-[var(--studio-content-top-inset,0px)]"
+ className="diffusion-surface media-header-layout @container relative flex h-full min-h-0 min-w-0 flex-1 flex-col overflow-hidden pt-[var(--studio-content-top-inset,0px)]"
>
<MediaRailResizeHandle kind="video" placement="page" className="hidden @[50rem]:block" />
{/* Portals to body, and this page stays mounted off-route, so gate it like the composer. */}
@@ -3768,7 +3768,7 @@ function VideoGenerator({
</Dialog>
{cpuExperimental ? <VideoCpuExperimentalBanner /> : null}
{/* Header: selector over the rail, Library link over the preview, as on Images and Audio. */}
- <div className="pointer-events-none relative z-40 grid h-[calc(48px*var(--ui-space-scale,1))] shrink-0 grid-cols-[minmax(0,var(--media-rail-width,calc(408px*var(--ui-space-scale,1))))_minmax(13rem,1fr)] @max-[30rem]:grid-cols-[minmax(0,1fr)_auto]">
+ <div className="pointer-events-none relative z-40 grid h-[calc(48px*var(--ui-space-scale,1))] shrink-0 grid-cols-[minmax(0,var(--media-rail-width,calc(408px*var(--ui-space-scale,1))))_minmax(var(--media-header-min-width),1fr)] @max-[30rem]:grid-cols-[minmax(0,1fr)_auto]">
<div
className={cn(
"pointer-events-none flex h-full min-w-0 items-start overflow-hidden @[50rem]:border-r @[50rem]:border-border/60",
@@ -3898,7 +3898,7 @@ function VideoGenerator({
<div className="flex min-h-0 w-full min-w-0 flex-1 flex-col overflow-y-auto overflow-x-hidden @[50rem]:flex-row @[50rem]:overflow-hidden">
<div
data-tour="video-settings"
- className="flex w-full shrink-0 flex-col border-b border-border/60 @[50rem]:w-[min(var(--media-rail-width,calc(408px*var(--ui-space-scale,1))),calc(100%-13rem))] @[50rem]:overflow-hidden @[50rem]:border-r @[50rem]:border-b-0"
+ className="flex w-full shrink-0 flex-col border-b border-border/60 @[50rem]:w-[min(var(--media-rail-width,calc(408px*var(--ui-space-scale,1))),calc(100%-var(--media-header-min-width)))] @[50rem]:overflow-hidden @[50rem]:border-r @[50rem]:border-b-0"
>
<div
ref={attachSettingsScroll}
diff --git a/studio/frontend/src/index.css b/studio/frontend/src/index.css
index b511fe1ca51..88fb8894186 100644
--- a/studio/frontend/src/index.css
+++ b/studio/frontend/src/index.css
@@ -55,6 +55,18 @@
}
@layer components {
+ .media-header-layout {
+ /* Header column, settings rail and resize handle share this boundary. */
+ --media-header-min-width: calc(14rem * var(--ui-space-scale, 1) + var(--studio-chat-header-right-inset, var(--studio-window-control-inset, 0px)));
+ }
+
+ /* Stacked layout: the model selector keeps at least half the header row. */
+ @container (width < 50rem) {
+ .media-header-layout > * {
+ --media-header-min-width: min(calc(14rem * var(--ui-space-scale, 1) + var(--studio-chat-header-right-inset, var(--studio-window-control-inset, 0px))), 50%);
+ }
+ }
+
/* The custom Windows/Linux titlebar stays above modal backdrops so native
window actions remain usable. Repeat the standard backdrop over the surface
and page navigation. Window controls paint above it, keeping their glyphs
diff --git a/studio/frontend/tests/media-rail-resize-cap.test.ts b/studio/frontend/tests/media-rail-resize-cap.test.ts
new file mode 100644
index 00000000000..d5e903cc7c6
--- /dev/null
+++ b/studio/frontend/tests/media-rail-resize-cap.test.ts
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import assert from "node:assert/strict";
+import test from "node:test";
+import ts from "@typescript/typescript6";
+import { readSrc } from "./helpers/kit.ts";
+
+// Runs the real layout effect on stubbed DOM sizes, without React.
+const source = ts.createSourceFile(
+ "media-rail-resize-handle.tsx",
+ readSrc("components/media-rail-resize-handle.tsx"),
+ ts.ScriptTarget.Latest,
+ true,
+ ts.ScriptKind.TSX,
+);
+let effectSource = "";
+function visit(node: ts.Node): void {
+ if (ts.isCallExpression(node) && node.expression.getText(source) === "useLayoutEffect") {
+ effectSource = node.arguments[0].getText(source);
+ }
+ ts.forEachChild(node, visit);
+}
+visit(source);
+assert.ok(effectSource, "the rail cap must update from actual layout measurements");
+const runEffect = new Function(
+ "anchorRef", "placement", "rail", "kind", "getComputedStyle", "document", "ResizeObserver", "setCap",
+ `return (${effectSource})();`,
+);
+
+function measure({
+ kind = "images", scale = 1, inset = "", fallbackInset = "", placement = "page",
+}: {
+ kind?: "images" | "video" | "audio";
+ scale?: number;
+ inset?: string;
+ fallbackInset?: string;
+ placement?: "page" | "rail";
+} = {}) {
+ const block = { clientWidth: 1000 };
+ const root = {};
+ let cap = NaN;
+ let update = () => {};
+ let disconnected = false;
+ const cleanup = runEffect(
+ { current: { parentElement: placement === "page" ? block : { parentElement: block } } },
+ placement, { scale }, kind,
+ (element: unknown) => element === root ? { fontSize: "16px" } : {
+ paddingLeft: "24px", paddingRight: "24px",
+ getPropertyValue: (name: string) => name === "--studio-chat-header-right-inset" ? inset : fallbackInset,
+ },
+ { documentElement: root },
+ class {
+ constructor(callback: () => void) { update = callback; }
+ observe(element: unknown) { assert.equal(element, block); }
+ disconnect() { disconnected = true; }
+ },
+ (value: number) => { cap = value; },
+ ) as () => void;
+ return {
+ get cap() { return cap; },
+ resize(width: number) { block.clientWidth = width; update(); },
+ cleanup() { cleanup(); assert.ok(disconnected); },
+ };
+}
+
+test("image and video drag/keyboard caps reserve the scaled compact toolbar", () => {
+ for (const kind of ["images", "video"] as const) {
+ const normal = measure({ kind });
+ assert.equal(normal.cap, 776);
+ normal.cleanup();
+ const enlarged = measure({ kind, scale: 2 });
+ assert.equal(enlarged.cap, 276);
+ enlarged.resize(1200);
+ assert.equal(enlarged.cap, 376);
+ enlarged.cleanup();
+ }
+});
+
+test("the header inset takes precedence, including zero, and window chrome is not scaled", () => {
+ const zero = measure({ inset: "0px", fallbackInset: "138px" });
+ assert.equal(zero.cap, 776);
+ zero.cleanup();
+ const fallback = measure({ fallbackInset: "138px", scale: 2 });
+ assert.equal(fallback.cap, 207);
+ fallback.cleanup();
+ const explicit = measure({ inset: "50px", fallbackInset: "138px", scale: 2 });
+ assert.equal(explicit.cap, 251);
+ explicit.cleanup();
+});
+
+test("audio retains its existing preview minimum and inset rail placement excludes padding", () => {
+ const audio = measure({ kind: "audio", scale: 2, inset: "138px" });
+ assert.equal(audio.cap, 396);
+ audio.cleanup();
+ const rail = measure({ placement: "rail" });
+ assert.equal(rail.cap, 728);
+ rail.cleanup();
+});
diff --git a/studio/frontend/tests/ui-font-size-scales-spacing.test.ts b/studio/frontend/tests/ui-font-size-scales-spacing.test.ts
index 10b9611854a..a49449c2b8b 100644
--- a/studio/frontend/tests/ui-font-size-scales-spacing.test.ts
+++ b/studio/frontend/tests/ui-font-size-scales-spacing.test.ts
@@ -348,15 +348,21 @@ test("a scaled media rail leaves the preview its minimum", () => {
"features/video/video-page.tsx",
]) {
const source = readSrc(file);
+ const minimum = file.includes("/audio/") ? "13rem" : "var(--media-header-min-width)";
assert.ok(
- source.includes(`@[50rem]:w-[min(${rail},calc(100%-13rem))]`),
+ source.includes(`@[50rem]:w-[min(${rail},calc(100%-${minimum}))]`),
`${file} rail can outgrow its split`,
);
assert.ok(
- source.includes(`grid-cols-[minmax(0,${rail})_minmax(13rem,1fr)]`),
+ source.includes(`grid-cols-[minmax(0,${rail})_minmax(${minimum},1fr)]`),
`${file} header column drifts from its rail`,
);
}
+ assert.match(
+ CSS,
+ /@container \(width < 50rem\) \{\s*\.media-header-layout > \* \{\s*--media-header-min-width: min\([^;]*, 50%\);/,
+ "the stacked header must leave the model selector half the row",
+ );
});
test("the settings rail never takes more than half the dialog", () => {
diff --git a/tests/studio/test_desktop_reliability_frontend_contract.py b/tests/studio/test_desktop_reliability_frontend_contract.py
index 970ca50cee6..b5c90b2ff13 100644
--- a/tests/studio/test_desktop_reliability_frontend_contract.py
+++ b/tests/studio/test_desktop_reliability_frontend_contract.py
@@ -1042,6 +1042,11 @@ RAIL_WIDTH_SCALED = (
"@[50rem]:w-[min(var(--media-rail-width,calc(408px*var(--ui-space-scale,1))),calc(100%-13rem))]"
)
HEADER_COLUMNS = "grid-cols-[minmax(0,var(--media-rail-width,408px))_minmax(13rem,1fr)]"
+# Images and Video reserve a UI-scaled minimum (index.css `.media-header-layout`); Audio keeps 13rem.
+MEDIA_MIN = "var(--media-header-min-width)"
+IMAGE_RAIL_WIDTH = RAIL_WIDTH.replace("13rem", MEDIA_MIN)
+IMAGE_RAIL_WIDTH_SCALED = RAIL_WIDTH_SCALED.replace("13rem", MEDIA_MIN)
+IMAGE_HEADER_COLUMNS = HEADER_COLUMNS.replace("13rem", MEDIA_MIN)
MEDIA_HEADER_ACTIONS = FRONTEND / "components/media-header-actions.tsx"
# Since #15919 the preview column is pill | links, the links' column never narrower than the links.
MEDIA_HEADER_ROW = "grid h-full min-w-0 grid-cols-[minmax(0,1fr)_auto_minmax(max-content,1fr)]"
@@ -2024,9 +2029,11 @@ def test_image_page_structural_panes_share_the_container_breakpoint():
assert "@container" in shell
assert "@[50rem]:flex-row @[50rem]:overflow-hidden" in section
- # Clamped so the canvas keeps the 13rem its header column reserves.
- assert RAIL_WIDTH in section
- assert RAIL_WIDTH_SCALED in IMAGES_PAGE.read_text(encoding = "utf-8"), "the rail stopped scaling"
+ # Clamped so the canvas keeps the minimum its header column reserves.
+ assert IMAGE_RAIL_WIDTH in section
+ assert IMAGE_RAIL_WIDTH_SCALED in IMAGES_PAGE.read_text(
+ encoding = "utf-8"
+ ), "the rail stopped scaling"
assert "md:flex-row" not in section
# pb-6 is only correct while the -action fade dissolves the last control into the footer.
assert "panel-scroll-fade-action" in section
@@ -2094,7 +2101,7 @@ def test_image_train_rail_matches_create_and_header():
step = r"(?:0|[1-9]\d*)(?:\.(?:25|5|75))?"
rail = re.search(
r"(?<=[\s\"])pl-10 max-sm:pl-5 @\[50rem\]:w-\[min\(var\(--media-rail-width,408px\),"
- rf"calc\(100%-13rem\+--spacing\(({step})\)\)\)\](?=[\s\"])",
+ rf"calc\(100%-var\(--media-header-min-width,13rem\)\+--spacing\(({step})\)\)\)\](?=[\s\"])",
layout,
)
assert rail, "the Train rail no longer uses the Create rail's width variable and clamp"
@@ -2201,7 +2208,7 @@ def test_images_header_tracks_preview_and_preserves_titlebar_controls():
)
assert "const { isMobile, pinned } = useSidebar();" in source
- assert HEADER_COLUMNS in opening
+ assert IMAGE_HEADER_COLUMNS in opening
assert "@[50rem]:border-r" in header
assert "isMobile" in header and "pl-12" in header
assert "!pinned && isTauri" in header