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.

Studio: dock the floating Live monitor beside Run settings (#11699)

Wasim Yousef Said80432b871a4c
diff --git a/studio/frontend/scripts/check-bundle-budget.ts b/studio/frontend/scripts/check-bundle-budget.ts
index 4daf81ee873..1d171ff6c69 100644
--- a/studio/frontend/scripts/check-bundle-budget.ts
+++ b/studio/frontend/scripts/check-bundle-budget.ts
@@ -39,6 +39,7 @@ export const BUDGET = {
// its own. Since that raise the eager set gained one 303-byte chunk (#11607's
// thread-message-slot split) and otherwise grew inside chunks already eager: #11607's fork
// boundary and #11648's UI scale, so what ran out is headroom, not laziness.
+ // The resource monitor remains eager so its frame can coordinate with overlays.
transferBytes: 1_770_000,
rawBytes: 5_950_000,
};
diff --git a/studio/frontend/src/components/floating-monitor-layout.ts b/studio/frontend/src/components/floating-monitor-layout.ts
new file mode 100644
index 00000000000..824aa681803
--- /dev/null
+++ b/studio/frontend/src/components/floating-monitor-layout.ts
@@ -0,0 +1,186 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+/**
+ * Where the Live resource monitor stands relative to the Run settings panel.
+ *
+ * The monitor and the panel share the bottom-right corner, and the monitor is
+ * the one that can move: docking it left of the panel leaves both usable. It
+ * yields instead where there is nowhere to dock to.
+ */
+
+/** The resting inset on every edge, `inset-4` at a 16px root font size. */
+export const FLOATING_MONITOR_EDGE_INSET = 16;
+/**
+ * The settings aside's resize handle is `-left-1 w-2`, so half of its target
+ * sits outside the aside. Both are Tailwind spacing utilities, which resolve
+ * through `--spacing: calc(0.25rem * var(--ui-space-scale, 1))` (index.css),
+ * so the outward half is 4px at the 15px default UI font and 5.333px at the
+ * 20px maximum. The monitor's layer paints above the aside and would
+ * otherwise swallow that outward half, so the clearance has to be derived
+ * from the live scale rather than pinned at the default's 4px.
+ */
+export const FLOATING_MONITOR_HANDLE_HALF_WIDTH = 4;
+
+/**
+ * The outward half of the resize handle at a given `--ui-space-scale`. Both
+ * callers can hand over a non-finite or non-positive reading (the CSS variable
+ * before the appearance store paints, or a cleared store), so anything that is
+ * not a usable scale falls back to the shipped 1:1 default.
+ */
+export function floatingMonitorHandleClearance(uiSpaceScale?: number): number {
+ const scale =
+ uiSpaceScale !== undefined && Number.isFinite(uiSpaceScale) && uiSpaceScale > 0
+ ? uiSpaceScale
+ : 1;
+ return FLOATING_MONITOR_HANDLE_HALF_WIDTH * scale;
+}
+
+/** The monitor's own width, `w-64`. */
+export const FLOATING_MONITOR_WIDTH = 256;
+
+export interface FloatingMonitorDockState {
+ isOpen: boolean;
+ isMobile: boolean;
+ isChatRoute: boolean;
+ settingsPanelOpen: boolean;
+ /** The panel's painted width, which leads the stored one during a drag. */
+ settingsWidth: number;
+ /** A pinned sidebar's width, 0 when it holds no column. */
+ sidebarWidth: number;
+ /** Viewport width; 0 or less means unknown, which skips the capacity check. */
+ viewportWidth: number;
+ /** The monitor's rendered width; natively resizable, so `w-64` is a floor. */
+ monitorWidth?: number;
+ /** Live --ui-space-scale; defaults to 1 before the appearance setting loads. */
+ uiSpaceScale?: number;
+}
+
+export interface FloatingMonitorLayout {
+ visible: boolean;
+ /**
+ * Hidden because the settings panel covers the corner, not because the user
+ * closed the monitor. The caller keeps the panel mounted so its geometry
+ * survives a temporary overlay.
+ */
+ suppressed: boolean;
+ dockedBesideRunSettings: boolean;
+}
+
+export function getFloatingMonitorLayout({
+ isOpen,
+ isMobile,
+ isChatRoute,
+ settingsPanelOpen,
+ settingsWidth,
+ sidebarWidth,
+ viewportWidth,
+ monitorWidth,
+ uiSpaceScale,
+}: FloatingMonitorDockState): FloatingMonitorLayout {
+ // The panel is chat-only and the store survives navigation, so a stale open
+ // flag on another route must not move the monitor.
+ const runSettingsVisible = isChatRoute && settingsPanelOpen;
+ // Docking needs room for the sidebar, the monitor and the panel at once.
+ // At the 768 px breakpoint the default 280 px sidebar and 272 px panel leave
+ // less than the monitor's own width, and a docked monitor would cover the
+ // sidebar instead of the panel.
+ const dockable =
+ !isMobile &&
+ dockedMonitorFits({
+ viewportWidth,
+ sidebarWidth,
+ settingsWidth,
+ monitorWidth,
+ uiSpaceScale,
+ });
+ const suppressed = isOpen && runSettingsVisible && !dockable;
+
+ return {
+ visible: isOpen && !suppressed,
+ suppressed,
+ dockedBesideRunSettings: isOpen && runSettingsVisible && dockable,
+ };
+}
+
+export function dockedMonitorFits({
+ viewportWidth,
+ sidebarWidth,
+ settingsWidth,
+ monitorWidth,
+ uiSpaceScale,
+}: {
+ viewportWidth: number;
+ sidebarWidth: number;
+ settingsWidth: number;
+ monitorWidth?: number;
+ uiSpaceScale?: number;
+}): boolean {
+ // An unmeasured window keeps the dock rather than hiding the monitor on a guess.
+ if (!(viewportWidth > 0)) {
+ return true;
+ }
+ const usable =
+ viewportWidth - Math.max(0, sidebarWidth) - Math.max(0, settingsWidth);
+ const scale =
+ uiSpaceScale !== undefined && Number.isFinite(uiSpaceScale) && uiSpaceScale > 0
+ ? uiSpaceScale
+ : 1;
+ // The monitor starts at the scaled left edge inset and ends at the panel's
+ // scaled resize-handle clearance; there is no second full edge inset on right.
+ const width =
+ monitorWidth === undefined || !Number.isFinite(monitorWidth)
+ ? FLOATING_MONITOR_WIDTH * scale
+ : monitorWidth;
+ return (
+ usable >=
+ width +
+ FLOATING_MONITOR_EDGE_INSET * scale +
+ floatingMonitorHandleClearance(scale)
+ );
+}
+
+/**
+ * The inset from the viewport's right edge, in px. Docked, the container ends
+ * where the panel begins, so the monitor clears it at every width the panel can
+ * be dragged to; a fixed offset is only correct at one width.
+ */
+export function floatingMonitorRightInset({
+ dockedBesideRunSettings,
+ settingsWidth,
+ uiSpaceScale = 1,
+}: {
+ dockedBesideRunSettings: boolean;
+ settingsWidth: number;
+ uiSpaceScale?: number;
+}): number {
+ return dockedBesideRunSettings
+ ? settingsWidth + floatingMonitorHandleClearance(uiSpaceScale)
+ : FLOATING_MONITOR_EDGE_INSET *
+ (Number.isFinite(uiSpaceScale) && uiSpaceScale > 0 ? uiSpaceScale : 1);
+}
+
+/**
+ * The constraint container's inline style. Returned as an object so the
+ * geometry a reviewer checks is the geometry the browser applies.
+ */
+export function floatingMonitorConstraintStyle({
+ zIndex,
+ dockedBesideRunSettings,
+ settingsWidth,
+ uiSpaceScale,
+}: {
+ zIndex: number;
+ dockedBesideRunSettings: boolean;
+ settingsWidth: number;
+ uiSpaceScale?: number;
+}): { zIndex: number; right: number } {
+ return {
+ zIndex,
+ right: floatingMonitorRightInset({
+ dockedBesideRunSettings,
+ settingsWidth,
+ uiSpaceScale,
+ }),
+ };
+}
diff --git a/studio/frontend/src/components/floating-monitor.tsx b/studio/frontend/src/components/floating-monitor.tsx
index 9577967bb43..c6bf540d0d6 100644
--- a/studio/frontend/src/components/floating-monitor.tsx
+++ b/studio/frontend/src/components/floating-monitor.tsx
@@ -3,6 +3,7 @@
import { Button } from "@/components/ui/button";
import { Progress } from "@/components/ui/progress";
+import { useChatRuntimeStore } from "@/features/chat/stores/chat-runtime-store";
import { FIND_PORTAL_ATTRIBUTE } from "@/features/find-in-page/lib/find-attributes";
import {
@@ -11,6 +12,10 @@ import {
} from "@/features/settings";
import { gpuMemoryDisplay } from "@/hooks/gpu-memory-display";
import { gpuMemoryTotalsGb, resolveGpuVramUsedGb } from "@/hooks/gpu-vram";
+import { useChatSettingsWidth } from "@/hooks/use-chat-settings-width";
+import { useIsMobile } from "@/hooks/use-mobile";
+import { useSidebarPin } from "@/hooks/use-sidebar-pin";
+import { useSidebarWidth } from "@/hooks/use-sidebar-width";
import { aggregateGpuMemoryTotalGb, useSystemInfo } from "@/hooks/use-system";
import { useT } from "@/i18n";
import {
@@ -18,6 +23,7 @@ import {
useFloatingPanelZIndex,
} from "@/lib/floating-panel-order";
import { cn } from "@/lib/utils";
+import { useRouterState } from "@tanstack/react-router";
import { CpuIcon, GripVerticalIcon, XIcon } from "lucide-react";
import { AnimatePresence, motion } from "motion/react";
import {
@@ -27,8 +33,16 @@ import {
useMemo,
useRef,
useState,
+ useSyncExternalStore,
} from "react";
+import {
+ FLOATING_MONITOR_WIDTH,
+ floatingMonitorConstraintStyle,
+ getFloatingMonitorLayout,
+} from "./floating-monitor-layout";
+import { useUiSpaceScale } from "@/hooks/use-ui-space-scale";
+
interface MonitorLayout {
left: number;
top: number;
@@ -100,7 +114,11 @@ function naturalWidth(monitor: HTMLDivElement): number {
return width;
}
-function useMonitorLayout(constraintsElement: HTMLDivElement | null) {
+function useMonitorLayout(
+ constraintsElement: HTMLDivElement | null,
+ narrowed: boolean,
+ hidden: boolean,
+) {
// This panel's claim on the shared frame. Reopening the monitor mid-exit
// mounts the replacement while the old panel is still animating out, and the
// old one unmounts last, so its cleanup must only clear its own frame.
@@ -110,12 +128,22 @@ function useMonitorLayout(constraintsElement: HTMLDivElement | null) {
const contentRef = useRef<HTMLDivElement>(null);
const dragSessionRef = useRef<DragSession | null>(null);
const dragFrameRef = useRef(0);
- const hasDraggedRef = useRef(false);
+ const hasDraggedLeftRef = useRef(false);
+ const hasDraggedTopRef = useRef(false);
const preferredWidthRef = useRef<number | null>(null);
const preferredHeightRef = useRef<number | null>(null);
const surfaceWidthRef = useRef(0);
+ const narrowedRef = useRef(narrowed);
+ const hiddenRef = useRef(hidden);
+ // The user's own placement while the container is at full width. Cleared when
+ // they drag while it is narrowed, which is a newer choice, not a clamp.
+ const chosenLeftRef = useRef<number | null>(null);
+ const restoreLeftRef = useRef<number | null>(null);
const remeasureRef = useRef(0);
const [layout, setLayout] = useState<MonitorLayout | null>(null);
+ // Reconcile normally arrives from the observers. A transition that leaves the
+ // constraint geometry untouched -- suppressed to undocked -- fires none.
+ const reconcileRef = useRef<(() => void) | null>(null);
useLayoutEffect(() => {
const monitor = monitorRef.current;
@@ -173,8 +201,18 @@ function useMonitorLayout(constraintsElement: HTMLDivElement | null) {
const maxTop = Math.max(0, constraintsBox.height - height);
const currentLeft = monitorBox.left - constraintsBox.left;
const currentTop = monitorBox.top - constraintsBox.top;
- const left = place(hasDraggedRef.current, currentLeft, maxLeft);
- const top = place(hasDraggedRef.current, currentTop, maxTop);
+ // A restored position is a deliberate left the constraint had clamped
+ // away, so it replaces `place()` for exactly one pass.
+ const restoreTo = restoreLeftRef.current;
+ const left =
+ restoreTo === null
+ ? place(hasDraggedLeftRef.current, currentLeft, maxLeft)
+ : clamp(restoreTo, 0, maxLeft);
+ restoreLeftRef.current = null;
+ if (!narrowedRef.current && hasDraggedLeftRef.current) {
+ chosenLeftRef.current = left;
+ }
+ const top = place(hasDraggedTopRef.current, currentTop, maxTop);
const session = dragSessionRef.current;
if (session) {
@@ -187,12 +225,14 @@ function useMonitorLayout(constraintsElement: HTMLDivElement | null) {
}
// Publish the real box so the overlay stack can keep clear of it.
- useMonitorFrameStore.getState().setFrame(publisher, {
- left: monitorBox.left,
- top: monitorBox.top,
- right: monitorBox.right,
- bottom: monitorBox.bottom,
- });
+ if (!hiddenRef.current) {
+ useMonitorFrameStore.getState().setFrame(publisher, {
+ left: monitorBox.left,
+ top: monitorBox.top,
+ right: monitorBox.right,
+ bottom: monitorBox.bottom,
+ });
+ }
setLayout((current) => {
// Mid-drag the offset lives in a transform, and the measured box already includes it, so
@@ -212,6 +252,7 @@ function useMonitorLayout(constraintsElement: HTMLDivElement | null) {
});
};
+ reconcileRef.current = reconcileGeometry;
reconcileGeometry();
const observer = new ResizeObserver(reconcileGeometry);
observer.observe(constraints);
@@ -223,6 +264,7 @@ function useMonitorLayout(constraintsElement: HTMLDivElement | null) {
}
return () => {
observer.disconnect();
+ reconcileRef.current = null;
useMonitorFrameStore.getState().clearFrame(publisher);
if (remeasureRef.current) {
cancelAnimationFrame(remeasureRef.current);
@@ -235,6 +277,31 @@ function useMonitorLayout(constraintsElement: HTMLDivElement | null) {
};
}, [constraintsElement, publisher]);
+ // Narrowing clamps the monitor left, and `place()` keeps the clamped spot.
+ // The position the user did drag to is put back when the container widens.
+ // Settled in a layout effect, before the next observation can reconcile.
+ // The API monitor treats any published frame as a live obstacle, so an
+ // invisible resource monitor must not keep publishing its box. Visibility and
+ // aria-hidden fire no ResizeObserver, so `hidden` also feeds the republish
+ // below: it is what restores the box once the monitor is on screen again.
+ useLayoutEffect(() => {
+ hiddenRef.current = hidden;
+ if (hidden) {
+ useMonitorFrameStore.getState().clearFrame(publisher);
+ }
+ }, [hidden, publisher]);
+
+ useLayoutEffect(() => {
+ if (narrowedRef.current === narrowed) {
+ return;
+ }
+ narrowedRef.current = narrowed;
+ if (!narrowed) {
+ restoreLeftRef.current = chosenLeftRef.current;
+ reconcileRef.current?.();
+ }
+ }, [narrowed]);
+
// ResizeObserver never fires for a position-only change, so dragging alone would leave the
// published frame at the monitor's old corner and the overlay stack dodging where it used to be.
// Re-publish once each layout is committed, which after a drag is on release: the frames in
@@ -243,7 +310,7 @@ function useMonitorLayout(constraintsElement: HTMLDivElement | null) {
useLayoutEffect(() => {
void layout;
const monitor = monitorRef.current;
- if (!(monitor && constraintsElement)) {
+ if (!(monitor && constraintsElement) || hiddenRef.current) {
return;
}
const box = monitor.getBoundingClientRect();
@@ -253,7 +320,7 @@ function useMonitorLayout(constraintsElement: HTMLDivElement | null) {
right: box.right,
bottom: box.bottom,
});
- }, [layout, constraintsElement, publisher]);
+ }, [layout, constraintsElement, publisher, hidden]);
function startDrag(event: PointerEvent<HTMLDivElement>) {
const monitor = monitorRef.current;
@@ -266,7 +333,6 @@ function useMonitorLayout(constraintsElement: HTMLDivElement | null) {
const monitorBox = monitor.getBoundingClientRect();
const left = monitorBox.left - constraintsBox.left;
const top = monitorBox.top - constraintsBox.top;
- hasDraggedRef.current = true;
// Native resize records attempted inline dimensions even when max-width
// or max-height hides them. Normalize only hidden dimensions so an
@@ -323,6 +389,9 @@ function useMonitorLayout(constraintsElement: HTMLDivElement | null) {
return;
}
+ // Horizontal placement is chosen on release. An intermediate move that
+ // returns to its starting X must leave an anchored monitor anchored.
+ const previousTop = session.top;
const left = clamp(
session.left + event.clientX - session.startX,
0,
@@ -333,6 +402,9 @@ function useMonitorLayout(constraintsElement: HTMLDivElement | null) {
0,
session.maxTop,
);
+ if (top !== previousTop) {
+ hasDraggedTopRef.current = true;
+ }
session.startX = event.clientX;
session.startY = event.clientY;
session.left = left;
@@ -351,8 +423,15 @@ function useMonitorLayout(constraintsElement: HTMLDivElement | null) {
cancelAnimationFrame(dragFrameRef.current);
dragFrameRef.current = 0;
}
- const { left, top, constraintsWidth, constraintsHeight } = session;
+ const { left, top, baseLeft, constraintsWidth, constraintsHeight } =
+ session;
dragSessionRef.current = null;
+ // Only the released horizontal position is a new choice. Returning to the
+ // starting X keeps the saved full-width position even after intermediate moves.
+ if (left !== baseLeft) {
+ hasDraggedLeftRef.current = true;
+ chosenLeftRef.current = narrowedRef.current ? null : left;
+ }
// Written to the node as well as to state, in this order, so handing the
// offset back to left/top cannot show a frame at the spot it started from.
const monitor = monitorRef.current;
@@ -417,13 +496,23 @@ function formatGiB(value: number): string {
}
interface FloatingMonitorPanelProps {
+ dockedBesideRunSettings: boolean;
onClose: () => void;
+ settingsWidth: number;
+ onRenderedWidth: (width: number) => void;
+ suppressed: boolean;
systemInfo: ReturnType<typeof useSystemInfo>;
+ /** The live `--ui-space-scale`; the resize handle's clearance follows it. */
+ uiSpaceScale: number;
}
-
function FloatingMonitorPanel({
+ dockedBesideRunSettings,
onClose,
+ onRenderedWidth,
+ settingsWidth,
+ suppressed,
systemInfo,
+ uiSpaceScale,
}: FloatingMonitorPanelProps) {
const t = useT();
const [constraintsElement, setConstraintsElement] =
@@ -436,7 +525,25 @@ function FloatingMonitorPanel({
startDrag,
updateDrag,
finishDrag,
- } = useMonitorLayout(constraintsElement);
+ } = useMonitorLayout(
+ constraintsElement,
+ dockedBesideRunSettings || suppressed,
+ suppressed,
+ );
+
+ // offsetWidth, not the bounding rect: the panel animates in from scale 0.94, and
+ // a rect read through that transform is short of the width it settles at.
+ useEffect(() => {
+ const monitor = monitorRef.current;
+ if (!monitor) {
+ return;
+ }
+ const measure = () => onRenderedWidth(monitor.offsetWidth);
+ measure();
+ const observer = new ResizeObserver(measure);
+ observer.observe(monitor);
+ return () => observer.disconnect();
+ }, [monitorRef, onRenderedWidth]);
const zIndex = useFloatingPanelZIndex("resource-monitor");
const raisePanel = useFloatingPanelOrderStore((state) => state.raise);
@@ -493,8 +600,22 @@ function FloatingMonitorPanel({
return (
<div
ref={setConstraintsElement}
- className="pointer-events-none fixed inset-4"
- style={{ zIndex }}
+ // The panel stays mounted while suppressed: the settings sheet is a
+ // temporary overlay, and unmounting would throw away the position and the
+ // browser-owned resize dimensions the user set. `invisible` keeps the box
+ // (and the observers watching it) while taking it off the screen.
+ aria-hidden={suppressed || undefined}
+ className={cn(
+ "pointer-events-none fixed inset-y-4 left-4",
+ suppressed && "invisible",
+ dockedBesideRunSettings ? undefined : "right-4",
+ )}
+ style={floatingMonitorConstraintStyle({
+ zIndex,
+ dockedBesideRunSettings,
+ settingsWidth,
+ uiSpaceScale,
+ })}
>
<motion.div
{...{ [FIND_PORTAL_ATTRIBUTE]: "" }}
@@ -671,13 +792,115 @@ function FloatingMonitorPanel({
}
export function FloatingMonitor() {
+ const uiSpaceScale = useUiSpaceScale();
const { isOpen, setIsOpen } = useMonitorOverlayStore();
- const systemInfo = useSystemInfo({ enabled: isOpen, pollMs: 5000 });
+ const settingsPanelOpen = useChatRuntimeStore((s) => s.settingsPanelOpen);
+ const pathname = useRouterState({ select: (s) => s.location.pathname });
+ const isMobile = useIsMobile();
+ // The panel's own rendered width: it is user-resizable from 248 to 560 px, so the
+ // docked offset has to come from the same value the panel paints at.
+ const { width: committedSettingsWidth } = useChatSettingsWidth();
+ const { pinned } = useSidebarPin();
+ const { width: committedSidebarWidth } = useSidebarWidth();
+ const isChatRoute = pathname === "/chat";
+
+ // Dragging the panel's edge paints `--chat-settings-width` straight onto the
+ // <aside> and commits to the store only on pointer up, so the store trails the
+ // panel by a whole drag. The monitor has to clear what is on screen, so it
+ // follows the painted width and falls back to the committed one.
+ const [paintedSettingsWidth, setPaintedSettingsWidth] = useState(0);
+ useEffect(() => {
+ if (!(isChatRoute && settingsPanelOpen)) {
+ setPaintedSettingsWidth(0);
+ return;
+ }
+ const panel = document.querySelector('[data-slot="chat-settings-panel"]');
+ if (!panel) {
+ setPaintedSettingsWidth(0);
+ return;
+ }
+ const measure = () => {
+ if (panel.isConnected) {
+ setPaintedSettingsWidth(panel.getBoundingClientRect().width);
+ }
+ };
+ measure();
+ const observer = new ResizeObserver(measure);
+ observer.observe(panel);
+ return () => observer.disconnect();
+ }, [isChatRoute, settingsPanelOpen, isMobile]);
+
+ // Same lag as the settings panel: the sidebar paints per frame and commits
+ // on release, so a docked monitor could sit under a grown sidebar.
+ const [paintedSidebarWidth, setPaintedSidebarWidth] = useState(0);
+ // Unpinning still holds the collapsed icon rail as a column on the web shell;
+ // `collapseToZero` is desktop-app only, and that rail is the one unpinned
+ // state that takes the monitor's room.
+ const [sidebarHoldsRail, setSidebarHoldsRail] = useState(false);
+ useEffect(() => {
+ const sidebar = document.querySelector('[data-slot="sidebar"]');
+ if (!sidebar) {
+ setPaintedSidebarWidth(0);
+ setSidebarHoldsRail(false);
+ return;
+ }
+ const measure = () => {
+ if (sidebar.isConnected) {
+ setPaintedSidebarWidth(sidebar.getBoundingClientRect().width);
+ setSidebarHoldsRail(
+ sidebar.getAttribute("data-collapsible") === "icon",
+ );
+ }
+ };
+ measure();
+ const observer = new ResizeObserver(measure);
+ observer.observe(sidebar);
+ return () => observer.disconnect();
+ }, [isMobile]);
+
+ // `useIsMobile` only notifies when the 768 px breakpoint is crossed, and the
+ // two width stores stop notifying at their maxima, so the capacity decision
+ // needs its own subscription or a plain resize never re-evaluates it.
+ const viewportWidth = useSyncExternalStore(
+ (onChange) => {
+ window.addEventListener("resize", onChange);
+ return () => window.removeEventListener("resize", onChange);
+ },
+ () => window.innerWidth,
+ () => 0,
+ );
+
+ const settingsWidth =
+ paintedSettingsWidth > 0 ? paintedSettingsWidth : committedSettingsWidth;
+ const pinnedSidebarWidth =
+ paintedSidebarWidth > 0 ? paintedSidebarWidth : committedSidebarWidth;
+ // A pinned sidebar holds its column; an unpinned one overlays the content, but
+ // the web shell still paints its collapsed icon rail as a column, so reserve
+ // that measured rail while it really is one.
+ const unpinnedSidebarWidth = sidebarHoldsRail ? paintedSidebarWidth : 0;
+ const sidebarWidth = pinned ? pinnedSidebarWidth : unpinnedSidebarWidth;
+ // The panel is natively resizable, so what it renders is what docking has to
+ // reserve. Before the first measure the constant is the floor.
+ const [monitorWidth, setMonitorWidth] = useState(FLOATING_MONITOR_WIDTH);
+ const { visible, suppressed, dockedBesideRunSettings } =
+ getFloatingMonitorLayout({
+ isOpen,
+ isMobile,
+ isChatRoute,
+ settingsPanelOpen,
+ settingsWidth,
+ sidebarWidth,
+ viewportWidth,
+ monitorWidth,
+ uiSpaceScale,
+ });
+ const systemInfo = useSystemInfo({ enabled: visible, pollMs: 5000 });
const [panelKey, setPanelKey] = useState(0);
const wasOpenRef = useRef(isOpen);
// Each visible panel owns native inline resize state. Advance the key on
// close so reopening during the exit animation still mounts fresh geometry.
+ // Docking and the mobile yield are not closes, so they do not advance it.
useEffect(() => {
if (wasOpenRef.current && !isOpen) {
setPanelKey((current) => current + 1);
@@ -687,9 +910,17 @@ export function FloatingMonitor() {
return (
<AnimatePresence>
- {isOpen && (
+ {(visible || suppressed) && (
<FloatingMonitorPanel
key={panelKey}
+ // The mobile sheet covers the panel rather than closing it, so the
+ // panel is kept mounted and invisible: the position and the size the
+ // user set survive the sheet being opened and closed.
+ suppressed={suppressed}
+ dockedBesideRunSettings={dockedBesideRunSettings}
+ settingsWidth={settingsWidth}
+ uiSpaceScale={uiSpaceScale}
+ onRenderedWidth={setMonitorWidth}
systemInfo={systemInfo}
onClose={() => setIsOpen(false)}
/>
diff --git a/studio/frontend/tests/floating-monitor-dock.test.ts b/studio/frontend/tests/floating-monitor-dock.test.ts
new file mode 100644
index 00000000000..75f983e8792
--- /dev/null
+++ b/studio/frontend/tests/floating-monitor-dock.test.ts
@@ -0,0 +1,204 @@
+// 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 { readFileSync } from "node:fs";
+import test from "node:test";
+
+import {
+ FLOATING_MONITOR_EDGE_INSET,
+ FLOATING_MONITOR_HANDLE_HALF_WIDTH,
+ dockedMonitorFits,
+ floatingMonitorConstraintStyle,
+ floatingMonitorHandleClearance,
+ getFloatingMonitorLayout,
+} from "../src/components/floating-monitor-layout.ts";
+import { UI_FONT_SIZE_RANGE } from "../src/features/settings/stores/appearance-custom-store.ts";
+
+const source = readFileSync(
+ new URL("../src/components/floating-monitor.tsx", import.meta.url),
+ "utf8",
+);
+const desktop = {
+ isOpen: true,
+ isMobile: false,
+ isChatRoute: true,
+ settingsPanelOpen: true,
+ settingsWidth: 272,
+ sidebarWidth: 280,
+ viewportWidth: 1440,
+};
+const docked = { visible: true, suppressed: false, dockedBesideRunSettings: true };
+const resting = { visible: true, suppressed: false, dockedBesideRunSettings: false };
+const yielded = { visible: false, suppressed: true, dockedBesideRunSettings: false };
+
+test("only a visible desktop monitor on the chat route docks beside Run settings", () => {
+ assert.deepEqual(getFloatingMonitorLayout(desktop), docked);
+ for (const [change, expected] of [
+ [{ isOpen: false }, { ...resting, visible: false }],
+ [{ isMobile: true }, yielded],
+ [{ settingsPanelOpen: false }, resting],
+ [{ isChatRoute: false }, resting],
+ [{ viewportWidth: 768 }, yielded],
+ ] as const) {
+ assert.deepEqual(getFloatingMonitorLayout({ ...desktop, ...change }), expected);
+ }
+});
+
+test("docking reserves the sidebar, scaled clearance, and rendered monitor width", () => {
+ const room = {
+ viewportWidth: 800,
+ sidebarWidth: 280,
+ settingsWidth: 290,
+ monitorWidth: 205,
+ uiSpaceScale: 0.8,
+ };
+ assert.equal(dockedMonitorFits(room), true);
+ assert.equal(dockedMonitorFits({ ...room, monitorWidth: 220 }), false);
+ assert.equal(dockedMonitorFits({ ...room, sidebarWidth: 300 }), false);
+ assert.equal(dockedMonitorFits({ ...room, viewportWidth: 0 }), true);
+ assert.deepEqual(getFloatingMonitorLayout({ ...desktop, ...room }), docked);
+ assert.deepEqual(
+ getFloatingMonitorLayout({ ...desktop, ...room, monitorWidth: 220 }),
+ yielded,
+ );
+ // A hand-resized monitor must not cover the collapsed web icon rail.
+ assert.equal(
+ dockedMonitorFits({ viewportWidth: 804, sidebarWidth: 48, settingsWidth: 272, monitorWidth: 500 }),
+ false,
+ );
+});
+
+test("the dock inset follows every panel width and supported UI font scale", () => {
+ const { min, default: base, max } = UI_FONT_SIZE_RANGE;
+ for (const settingsWidth of [248, 272, 320, 420, 560]) {
+ for (const uiSpaceScale of [min / base, 1, max / base]) {
+ const clearance = FLOATING_MONITOR_HANDLE_HALF_WIDTH * uiSpaceScale;
+ const style = floatingMonitorConstraintStyle({
+ zIndex: 9100,
+ dockedBesideRunSettings: true,
+ settingsWidth,
+ uiSpaceScale,
+ });
+ assert.deepEqual(style, { zIndex: 9100, right: settingsWidth + clearance });
+ assert.equal(floatingMonitorHandleClearance(uiSpaceScale), clearance);
+ // The monitor ends before the panel and its outward-facing resize handle.
+ assert.ok(1440 - style.right < 1440 - settingsWidth);
+ }
+ }
+ assert.ok(floatingMonitorHandleClearance(max / base) > FLOATING_MONITOR_HANDLE_HALF_WIDTH);
+});
+
+test("undocking restores a scaled corner inset, including for invalid scales", () => {
+ for (const [scale, expected] of [
+ [0.8, FLOATING_MONITOR_EDGE_INSET * 0.8],
+ [undefined, FLOATING_MONITOR_EDGE_INSET],
+ [0, FLOATING_MONITOR_EDGE_INSET],
+ [Number.NaN, FLOATING_MONITOR_EDGE_INSET],
+ ] as const) {
+ assert.equal(
+ floatingMonitorConstraintStyle({
+ zIndex: 9100,
+ dockedBesideRunSettings: false,
+ settingsWidth: 560,
+ uiSpaceScale: scale,
+ }).right,
+ expected,
+ );
+ if (!scale || Number.isNaN(scale)) {
+ assert.equal(floatingMonitorHandleClearance(scale), FLOATING_MONITOR_HANDLE_HALF_WIDTH);
+ }
+ }
+});
+test("a monitor fits at the exact dock boundary, but not one pixel below", () => {
+ const capacity = {
+ sidebarWidth: 280,
+ settingsWidth: 272,
+ monitorWidth: 256,
+ uiSpaceScale: 1,
+ };
+ // Both the left inset (16px) and the resize-handle clearance (4px)
+ // count toward the required available width.
+ const boundary = 280 + 272 + 256 + 16 + 4;
+ assert.equal(dockedMonitorFits({ ...capacity, viewportWidth: boundary }), true);
+ assert.equal(dockedMonitorFits({ ...capacity, viewportWidth: boundary - 1 }), false);
+});
+
+test("the monitor reads the panel's painted width and keeps its floating layer", () => {
+ const container = source.slice(source.indexOf("ref={setConstraintsElement}"));
+ assert.match(source, /const \{ width: committedSettingsWidth \} = useChatSettingsWidth\(\)/);
+ assert.match(source, /paintedSettingsWidth > 0 \? paintedSettingsWidth : committedSettingsWidth/);
+ assert.match(source, /new ResizeObserver\(measure\)[\s\S]*observer\.observe\(panel\)/);
+ assert.match(source, /const uiSpaceScale = useUiSpaceScale\(\)/);
+ assert.match(container, /floatingMonitorConstraintStyle\(\{[\s\S]*zIndex,[\s\S]*settingsWidth,[\s\S]*uiSpaceScale,/);
+ assert.match(source, /useFloatingPanelZIndex\("resource-monitor"\)/);
+ assert.doesNotMatch(container.slice(0, container.indexOf("<motion.div")), /\bz-\d+\b|\bright-\[\d+rem\]/);
+});
+
+test("responsive changes reattach geometry observers and recalculate capacity", () => {
+ assert.match(source, /\}, \[isChatRoute, settingsPanelOpen, isMobile\]\);/);
+ assert.match(source, /\}, \[isMobile\]\);/);
+ assert.match(source, /paintedSidebarWidth > 0 \? paintedSidebarWidth : committedSidebarWidth/);
+ assert.match(source, /const sidebarWidth = pinned \? pinnedSidebarWidth : unpinnedSidebarWidth/);
+ assert.match(source, /const viewportWidth = useSyncExternalStore\(/);
+ assert.match(source, /window\.addEventListener\("resize", onChange\)/);
+ assert.match(source, /onRenderedWidth=\{setMonitorWidth\}/);
+});
+
+test("suppression retains layout but does not publish a phantom frame", () => {
+ assert.match(source, /\(visible \|\| suppressed\) &&/);
+ assert.match(source, /suppressed && "invisible"/);
+ assert.match(source, /if \(hidden\) \{\s*useMonitorFrameStore\.getState\(\)\.clearFrame\(publisher\);/);
+ assert.match(source, /if \(!hiddenRef\.current\) \{\s*useMonitorFrameStore\.getState\(\)\.setFrame/);
+ assert.match(source, /\}, \[layout, constraintsElement, publisher, hidden\]\);/);
+});
+
+test("a net-zero docked drag must not discard the saved full-width X", () => {
+ const update = source.slice(source.indexOf("function updateDrag"), source.indexOf("function finishDrag"));
+ const finish = source.slice(source.indexOf("function finishDrag"));
+ // Intermediate pointer moves are provisional. Only a released horizontal
+ // displacement replaces the user's earlier full-width placement.
+ assert.doesNotMatch(update, /chosenLeftRef\.current = null/);
+ assert.match(finish, /if \(left !== baseLeft\) \{\s*hasDraggedLeftRef\.current = true;\s*chosenLeftRef\.current = narrowedRef\.current \? null : left;/);
+ assert.match(source, /restoreLeftRef\.current = chosenLeftRef\.current/);
+ assert.match(source, /if \(!narrowed\) \{\s*restoreLeftRef\.current = chosenLeftRef\.current;\s*reconcileRef\.current\?\.\(\);/);
+ assert.match(source, /place\(hasDraggedTopRef\.current, currentTop, maxTop\)/);
+});
+
+test("the panel width clamps to the same bounds used by docking", async () => {
+ const { clampChatSettingsWidth } = await import("../src/hooks/use-chat-settings-width.ts");
+ for (const width of [248, 272, 320, 420, 560]) {
+ const settingsWidth = clampChatSettingsWidth(width);
+ assert.equal(settingsWidth, width);
+ assert.equal(
+ floatingMonitorConstraintStyle({
+ zIndex: 9100,
+ dockedBesideRunSettings: true,
+ settingsWidth,
+ }).right,
+ width + FLOATING_MONITOR_HANDLE_HALF_WIDTH,
+ );
+ }
+ assert.equal(clampChatSettingsWidth(200), 248);
+ assert.equal(clampChatSettingsWidth(600), 560);
+});
+
+test("spacing and the resize handle use the same live UI scale", () => {
+ const css = readFileSync(new URL("../src/index.css", import.meta.url), "utf8");
+ const handle = readFileSync(
+ new URL("../src/components/ui/panel-resize-handle.tsx", import.meta.url),
+ "utf8",
+ );
+ assert.match(css, /--spacing:\s*calc\(0\.25rem \* var\(--ui-space-scale, 1\)\)/);
+ assert.match(css, /--ui-space-scale:\s*calc\(var\(--ui-font-scale, 1\) \/ 0\.9375\)/);
+ assert.match(handle, /edge === "left" \? "-left-1" : "-right-1"/);
+ assert.match(source, /const uiSpaceScale = useUiSpaceScale\(\)/);
+});
+
+test("docking never remounts the monitor or loses its drag geometry", () => {
+ assert.doesNotMatch(source, /key=\{`\$\{panelKey\}-/);
+ assert.match(source, /useLayoutEffect\(\(\) => \{\s*if \(narrowedRef\.current === narrowed\)/);
+ assert.match(source, /const restoreTo = restoreLeftRef\.current;/);
+ assert.match(source, /place\(hasDraggedLeftRef\.current, currentLeft, maxLeft\)/);
+ assert.match(source, /const unpinnedSidebarWidth = sidebarHoldsRail \? paintedSidebarWidth : 0/);
+});
diff --git a/tests/studio/test_overlay_layering.py b/tests/studio/test_overlay_layering.py
index 06aeab537b5..e013547ea7d 100644
--- a/tests/studio/test_overlay_layering.py
+++ b/tests/studio/test_overlay_layering.py
@@ -88,9 +88,12 @@ def test_both_floating_panels_stack_on_the_shared_layer(path: Path):
Sharing the layer is what lets the one the user touched last come forward,
which is the only way out of a monitor resized over the whole viewport."""
container = _container(path, "setConstraintsElement")
- assert "style={{ zIndex }}" in container, (
- f"{path.name}: the panel container no longer takes its z-index from the "
- f"floating panel order store: {container!r}"
+ style_applies_shared_layer = "style={{ zIndex }}" in container or re.search(
+ r"style=\{floatingMonitorConstraintStyle\(\{\s*zIndex,", container
+ )
+ assert style_applies_shared_layer, (
+ f"{path.name}: the panel container no longer applies the floating panel "
+ f"order store's z-index: {container!r}"
)
assert not _Z.search(container), (
f"{path.name}: the panel container still carries a hard-coded z-index, "