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.

Unsloth Studio / Desktop: keep floating panels where they were left across resizes, minimize and restarts (#14355)

Daniel Han8a07b9c5b2ad
diff --git a/studio/frontend/scripts/check-bundle-budget.ts b/studio/frontend/scripts/check-bundle-budget.ts
index d5bb4df6190..e66a13b2c72 100644
--- a/studio/frontend/scripts/check-bundle-budget.ts
+++ b/studio/frontend/scripts/check-bundle-budget.ts
@@ -341,8 +341,9 @@ export const BUDGET = {
// The MCP app tool arguments on the approval card (#14458) in the eager chat UI add 341 B raw / 110 B transfer
// (6,862,706 -> 6,863,047 B raw, 2,066,422 -> 2,066,532 B transfer against 2aeeceb07e, one machine and build,
// 96 chunks). Raised by that.
- transferBytes: 2_070_999,
- rawBytes: 6_877_089,
+ // Floating panels remembering their dropped spot (#14355) add 701 B raw / 211 B transfer. Raised by that.
+ transferBytes: 2_071_210,
+ rawBytes: 6_877_790,
};
// The chunk count is reported but not budgeted. Splitting a page out of the entry raises it while lowering the
diff --git a/studio/frontend/src/components/floating-monitor.tsx b/studio/frontend/src/components/floating-monitor.tsx
index 43f0073fcaa..bef44c9a30b 100644
--- a/studio/frontend/src/components/floating-monitor.tsx
+++ b/studio/frontend/src/components/floating-monitor.tsx
@@ -1,6 +1,7 @@
// 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 { FLOATING_PANEL_POSITION_KEYS } from "@/hooks/floating-panel-position";
import { useFloatingPanelLayout } from "@/hooks/use-floating-panel-layout";
import { Button } from "@/components/ui/button";
import { Progress } from "@/components/ui/progress";
@@ -147,6 +148,8 @@ function FloatingMonitorPanel({
constraintsElement,
dockedBesideRunSettings || suppressed,
suppressed,
+ undefined,
+ FLOATING_PANEL_POSITION_KEYS.liveMonitor,
);
// offsetWidth, not the bounding rect: the panel animates in from scale 0.94, and
diff --git a/studio/frontend/src/features/api-monitor/api-monitor-overlay.tsx b/studio/frontend/src/features/api-monitor/api-monitor-overlay.tsx
index 7bb638bd9b2..2f72f676362 100644
--- a/studio/frontend/src/features/api-monitor/api-monitor-overlay.tsx
+++ b/studio/frontend/src/features/api-monitor/api-monitor-overlay.tsx
@@ -12,6 +12,7 @@ import type {
} from "@/features/chat/types/api";
import { FIND_PORTAL_ATTRIBUTE } from "@/features/find-in-page/lib/find-attributes";
import { useMonitorFrameStore, useShortcut } from "@/features/settings";
+import { FLOATING_PANEL_POSITION_KEYS } from "@/hooks/floating-panel-position";
import { useFloatingPanelLayout } from "@/hooks/use-floating-panel-layout";
import {
useFloatingPanelOrderStore,
@@ -359,6 +360,7 @@ function ApiMonitorPanel({
top: initial.top - bounds.top,
};
},
+ FLOATING_PANEL_POSITION_KEYS.apiMonitor,
);
const frames = useMonitorFrameStore((state) => state.frames);
const ownFrame = frames.get(publisher);
diff --git a/studio/frontend/src/features/loaded-models/use-drag-position.ts b/studio/frontend/src/features/loaded-models/use-drag-position.ts
index 0334c1dd852..c3ed97ac7f4 100644
--- a/studio/frontend/src/features/loaded-models/use-drag-position.ts
+++ b/studio/frontend/src/features/loaded-models/use-drag-position.ts
@@ -5,7 +5,8 @@
// user moves it, then kept where they left it. Absolute viewport coordinates rather than a
// transform, so the position survives a reload and can be clamped when the window changes size.
-import { useCallback, useEffect, useRef, useState } from "react";
+import { isDegenerateBox } from "../../hooks/floating-panel-position.ts";
+import { useCallback, useEffect, useMemo, useRef, useState } from "react";
export type DragPosition = { left: number; top: number };
@@ -92,15 +93,26 @@ export type UseDragPosition = {
};
+type Fit = { width: number; height: number; viewport: Viewport };
+
export function useDragPosition(storageKey: string): UseDragPosition {
- const [position, setPosition] = useState<DragPosition | null>(() => {
- if (typeof window === "undefined") return null;
- const stored = readStored(storageKey);
- // Clamp on read as well as on resize. The observer below cannot fire until after the first
- // paint, so a position saved on a wider screen would flash off screen once; zero width/height
- // keeps at least the top-left corner in view, and the first measurement refines it.
- return stored ? clampToViewport(stored, 0, 0, viewport()) : null;
- });
+ // User's spot; clamps never write back, so a shrink or 0x0 minimize cannot lose it.
+ const [chosen, setPosition] = useState<DragPosition | null>(() =>
+ typeof window === "undefined" ? null : readStored(storageKey),
+ );
+ // Zero size until measured keeps a wider-screen spot's top-left corner in view before first paint.
+ const [fit, setFit] = useState<Fit>(() => ({
+ width: 0,
+ height: 0,
+ viewport: typeof window === "undefined" ? { width: 0, height: 0 } : viewport(),
+ }));
+ const position = useMemo(
+ () =>
+ chosen
+ ? clampToViewport(chosen, fit.width, fit.height, fit.viewport)
+ : null,
+ [chosen, fit],
+ );
// Held from pointerdown to pointerup; dragging only once past the threshold.
const [pressing, setPressing] = useState(false);
const [dragging, setDragging] = useState(false);
@@ -133,20 +145,22 @@ export function useDragPosition(storageKey: string): UseDragPosition {
// Returning the same object when nothing changed matters: this also runs from
// a ResizeObserver, and a fresh object every time would re-render forever.
const reclamp = useCallback((width: number, height: number) => {
- setPosition((current) => {
- if (!current) return current;
- const next = clampToViewport(current, width, height, viewport());
- return next.left === current.left && next.top === current.top
+ const view = viewport();
+ if (isDegenerateBox(view)) return;
+ setFit((current) =>
+ current.width === width &&
+ current.height === height &&
+ current.viewport.width === view.width &&
+ current.viewport.height === view.height
? current
- : next;
- });
+ : { width, height, viewport: view },
+ );
}, []);
// A window that shrank, or a panel that grew when expanded, would otherwise strand it off screen
// with nothing able to bring it back. Deliberately not keyed on `position`: it used to be, so
// every frame of a drag tore the observer down and built a new one, and observing re-measures,
- // which forced a synchronous layout each time. reclamp is a no-op until the panel has a position,
- // so attaching on mount costs nothing.
+ // which forced a synchronous layout each time. reclamp returns the same object when unchanged.
useEffect(() => {
if (!panelEl) return;
const measure = () => {
diff --git a/studio/frontend/src/features/settings/tabs/general-tab.tsx b/studio/frontend/src/features/settings/tabs/general-tab.tsx
index dee86c457cc..b0a8b695a04 100644
--- a/studio/frontend/src/features/settings/tabs/general-tab.tsx
+++ b/studio/frontend/src/features/settings/tabs/general-tab.tsx
@@ -28,6 +28,7 @@ import {
emitTrainingRunsChanged,
TRAINING_UI_PREFERENCE_KEYS,
} from "@/features/training";
+import { FLOATING_PANEL_POSITION_KEYS } from "@/hooks/floating-panel-position";
import { NOTIFICATION_PREF_KEYS } from "@/hooks/use-notification-frequency";
import { useHfTokenValidation } from "@/hooks";
import { LOCALE_STORAGE_KEY, useT } from "@/i18n";
@@ -177,6 +178,7 @@ const PREFS_KEYS: string[] = [
LOADED_MODELS_PREFERENCE_KEYS.collapsed,
LOADED_MODELS_PREFERENCE_KEYS.position,
LOADED_MODELS_PREFERENCE_KEYS.dismissed,
+ ...Object.values(FLOATING_PANEL_POSITION_KEYS),
// Voice settings
"unsloth_voice_settings",
// Retired keys. The onboarding wizard is gone, but installs that ran it still
diff --git a/studio/frontend/src/hooks/floating-panel-position.ts b/studio/frontend/src/hooks/floating-panel-position.ts
new file mode 100644
index 00000000000..ddb55da99ab
--- /dev/null
+++ b/studio/frontend/src/hooks/floating-panel-position.ts
@@ -0,0 +1,47 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+export const FLOATING_PANEL_POSITION_KEYS = {
+ liveMonitor: "unsloth_live_monitor_position",
+ apiMonitor: "unsloth_api_monitor_position",
+} as const;
+
+/** User's drop spot in its constraints box; a null axis stays anchored to the far edge. */
+export type PanelIntent = { left: number | null; top: number | null };
+
+function axis(value: unknown): number | null | undefined {
+ if (value === null) return null;
+ return typeof value === "number" && Number.isFinite(value) ? value : undefined;
+}
+
+export function readPanelIntent(key: string | undefined): PanelIntent | null {
+ if (!key) return null;
+ try {
+ const raw = localStorage.getItem(key);
+ if (!raw) return null;
+ const parsed = JSON.parse(raw) as Record<string, unknown> | null;
+ const left = axis(parsed?.left);
+ const top = axis(parsed?.top);
+ return left === undefined || top === undefined ? null : { left, top };
+ } catch {
+ return null;
+ }
+}
+
+export function storePanelIntent(key: string | undefined, intent: PanelIntent): void {
+ if (!key) return;
+ try {
+ localStorage.setItem(key, JSON.stringify(intent));
+ } catch {
+ // storage unavailable
+ }
+}
+
+export function placeAxis(intent: number | null, max: number): number {
+ return intent === null ? max : Math.max(0, Math.min(max, intent));
+}
+
+/** Minimized Windows Desktop resizes the page to 0x0 (tao); laying out against it parks panels top-left. */
+export function isDegenerateBox(box: { width: number; height: number }): boolean {
+ return !(box.width > 0 && box.height > 0);
+}
diff --git a/studio/frontend/src/hooks/use-floating-panel-layout.ts b/studio/frontend/src/hooks/use-floating-panel-layout.ts
index 03f496f586d..366b4987067 100644
--- a/studio/frontend/src/hooks/use-floating-panel-layout.ts
+++ b/studio/frontend/src/hooks/use-floating-panel-layout.ts
@@ -2,6 +2,13 @@
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
import { useMonitorFrameStore } from "@/features/settings";
+import {
+ type PanelIntent,
+ isDegenerateBox,
+ placeAxis,
+ readPanelIntent,
+ storePanelIntent,
+} from "@/hooks/floating-panel-position";
import {
type PointerEvent,
useLayoutEffect,
@@ -38,11 +45,6 @@ function clamp(value: number, min: number, max: number): number {
return Math.max(min, Math.min(max, value));
}
-// Anchored to the far edge until the user drags, then clamped where they left it.
-function place(dragged: boolean, current: number, max: number): number {
- return dragged ? clamp(current, 0, max) : max;
-}
-
function sameLayout(a: MonitorLayout, b: MonitorLayout): boolean {
return (
a.left === b.left &&
@@ -84,6 +86,7 @@ export function useFloatingPanelLayout(
size: { width: number; height: number },
bounds: DOMRect,
) => { left: number; top: number },
+ storageKey?: string,
) {
// Per-instance frame owner: a panel unmounting mid-exit clears only its own frame.
const publisher = useMemo(() => ({}), []);
@@ -92,16 +95,14 @@ export function useFloatingPanelLayout(
const contentRef = useRef<HTMLDivElement>(null);
const dragSessionRef = useRef<DragSession | null>(null);
const dragFrameRef = useRef(0);
- const hasDraggedLeftRef = useRef(false);
- const hasDraggedTopRef = useRef(false);
+ // User's spot, never rewritten by a clamp.
+ const [storedIntent] = useState(() => readPanelIntent(storageKey));
+ const intentRef = useRef<PanelIntent>(storedIntent ?? { left: null, top: null });
const preferredWidthRef = useRef<number | null>(null);
const preferredHeightRef = useRef<number | null>(null);
const surfaceWidthRef = useRef(0);
const narrowedRef = useRef(narrowed);
const hiddenRef = useRef(hidden);
- // User's full-width placement; cleared by a drag while narrowed.
- const chosenLeftRef = useRef<number | null>(null);
- const restoreLeftRef = useRef<number | null>(null);
const remeasureRef = useRef(0);
const [layout, setLayout] = useState<MonitorLayout | null>(null);
// For transitions that fire no observer (suppressed to undocked).
@@ -133,6 +134,9 @@ export function useFloatingPanelLayout(
const reconcileGeometry = () => {
const constraintsBox = constraints.getBoundingClientRect();
+ if (isDegenerateBox(constraintsBox)) {
+ return;
+ }
const monitorBox = monitor.getBoundingClientRect();
const desiredHeight = desiredPanelHeight(
monitorBox.height,
@@ -158,32 +162,30 @@ export function useFloatingPanelLayout(
);
const maxLeft = Math.max(0, constraintsBox.width - width);
const maxTop = Math.max(0, constraintsBox.height - height);
- const currentLeft = monitorBox.left - constraintsBox.left;
- const currentTop = monitorBox.top - constraintsBox.top;
- const restoreTo = restoreLeftRef.current;
- let left =
- restoreTo === null
- ? place(hasDraggedLeftRef.current, currentLeft, maxLeft)
- : clamp(restoreTo, 0, maxLeft);
- restoreLeftRef.current = null;
- if (!narrowedRef.current && hasDraggedLeftRef.current) {
- chosenLeftRef.current = left;
- }
- let top = place(hasDraggedTopRef.current, currentTop, maxTop);
- // Obstacle avoidance applies to the first placement only.
- if (!initializedRef.current && initialPlacementRef.current) {
+ const session = dragSessionRef.current;
+ // Mid-drag the measured box (transform included) is where the pointer has it.
+ let left = session
+ ? clamp(monitorBox.left - constraintsBox.left, 0, maxLeft)
+ : placeAxis(intentRef.current.left, maxLeft);
+ let top = session
+ ? clamp(monitorBox.top - constraintsBox.top, 0, maxTop)
+ : placeAxis(intentRef.current.top, maxTop);
+ // Obstacle avoidance applies to the first placement only, and a remembered spot wins.
+ if (
+ !initializedRef.current &&
+ initialPlacementRef.current &&
+ storedIntent === null
+ ) {
const initial = initialPlacementRef.current(
{ width, height },
constraintsBox,
);
left = clamp(initial.left, 0, maxLeft);
top = clamp(initial.top, 0, maxTop);
- hasDraggedLeftRef.current = true;
- hasDraggedTopRef.current = true;
+ intentRef.current = { left, top };
}
initializedRef.current = true;
- const session = dragSessionRef.current;
if (session) {
session.left = left;
session.top = top;
@@ -240,7 +242,7 @@ export function useFloatingPanelLayout(
dragFrameRef.current = 0;
}
};
- }, [constraintsElement, publisher]);
+ }, [constraintsElement, publisher, storedIntent]);
// A hidden panel must not publish a frame others dodge.
useLayoutEffect(() => {
@@ -256,7 +258,6 @@ export function useFloatingPanelLayout(
}
narrowedRef.current = narrowed;
if (!narrowed) {
- restoreLeftRef.current = chosenLeftRef.current;
reconcileRef.current?.();
}
}, [narrowed]);
@@ -340,7 +341,6 @@ export function useFloatingPanelLayout(
return;
}
- const previousTop = session.top;
const left = clamp(
session.left + event.clientX - session.startX,
0,
@@ -351,9 +351,6 @@ export function useFloatingPanelLayout(
0,
session.maxTop,
);
- if (top !== previousTop) {
- hasDraggedTopRef.current = true;
- }
session.startX = event.clientX;
session.startY = event.clientY;
session.left = left;
@@ -372,12 +369,22 @@ export function useFloatingPanelLayout(
cancelAnimationFrame(dragFrameRef.current);
dragFrameRef.current = 0;
}
- const { left, top, baseLeft, constraintsWidth, constraintsHeight } =
- session;
+ const {
+ left,
+ top,
+ baseLeft,
+ baseTop,
+ constraintsWidth,
+ constraintsHeight,
+ } = session;
dragSessionRef.current = null;
- if (left !== baseLeft) {
- hasDraggedLeftRef.current = true;
- chosenLeftRef.current = narrowedRef.current ? null : left;
+ if (left !== baseLeft || top !== baseTop) {
+ const intent = intentRef.current;
+ intentRef.current = {
+ left: left !== baseLeft ? left : intent.left,
+ top: top !== baseTop ? top : intent.top,
+ };
+ storePanelIntent(storageKey, intentRef.current);
}
// Write the node before state so the handoff never flashes the start position.
const monitor = monitorRef.current;
diff --git a/studio/frontend/tests/floating-monitor-dock.test.ts b/studio/frontend/tests/floating-monitor-dock.test.ts
index 402146e1812..a53c1b48a30 100644
--- a/studio/frontend/tests/floating-monitor-dock.test.ts
+++ b/studio/frontend/tests/floating-monitor-dock.test.ts
@@ -162,13 +162,12 @@ test("suppression retains layout but does not publish a phantom frame", () => {
test("a net-zero docked drag must not discard the saved full-width X", () => {
const update = layoutSource.slice(layoutSource.indexOf("function updateDrag"), layoutSource.indexOf("function finishDrag"));
const finish = layoutSource.slice(layoutSource.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(layoutSource, /restoreLeftRef\.current = chosenLeftRef\.current/);
- assert.match(layoutSource, /if \(!narrowed\) \{\s*restoreLeftRef\.current = chosenLeftRef\.current;\s*reconcileRef\.current\?\.\(\);/);
- assert.match(layoutSource, /place\(hasDraggedTopRef\.current, currentTop, maxTop\)/);
+ // Only a released drag replaces the stored spot, per axis.
+ assert.doesNotMatch(update, /intentRef\.current/);
+ assert.match(finish, /left: left !== baseLeft \? left : intent\.left,/);
+ assert.match(finish, /top: top !== baseTop \? top : intent\.top,/);
+ assert.match(layoutSource, /if \(!narrowed\) \{\s*reconcileRef\.current\?\.\(\);/);
+ assert.match(layoutSource, /placeAxis\(intentRef\.current\.top, maxTop\)/);
});
test("the panel width clamps to the same bounds used by docking", async () => {
@@ -204,7 +203,6 @@ test("spacing and the resize handle use the same live UI scale", () => {
test("docking never remounts the monitor or loses its drag geometry", () => {
assert.doesNotMatch(source, /key=\{`\$\{panelKey\}-/);
assert.match(layoutSource, /useLayoutEffect\(\(\) => \{\s*if \(narrowedRef\.current === narrowed\)/);
- assert.match(layoutSource, /const restoreTo = restoreLeftRef\.current;/);
- assert.match(layoutSource, /place\(hasDraggedLeftRef\.current, currentLeft, maxLeft\)/);
+ assert.match(layoutSource, /placeAxis\(intentRef\.current\.left, maxLeft\)/);
assert.match(source, /const unpinnedSidebarWidth = sidebarHoldsRail \? paintedSidebarWidth : 0/);
});
diff --git a/studio/frontend/tests/floating-panel-position.test.ts b/studio/frontend/tests/floating-panel-position.test.ts
new file mode 100644
index 00000000000..50002c1f632
--- /dev/null
+++ b/studio/frontend/tests/floating-panel-position.test.ts
@@ -0,0 +1,112 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+// #14330: a clamp (e.g. the 0x0 Windows minimize) became the panel's new home.
+
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import { clampToViewport } from "../src/features/loaded-models/use-drag-position.ts";
+import {
+ FLOATING_PANEL_POSITION_KEYS,
+ isDegenerateBox,
+ placeAxis,
+ readPanelIntent,
+ storePanelIntent,
+} from "../src/hooks/floating-panel-position.ts";
+
+import { readSrc } from "./helpers/kit.ts";
+
+function withStorage(run: (store: Map<string, string>) => void): void {
+ const store = new Map<string, string>();
+ const previous = (globalThis as { localStorage?: unknown }).localStorage;
+ (globalThis as { localStorage?: unknown }).localStorage = {
+ getItem: (key: string) => store.get(key) ?? null,
+ setItem: (key: string, value: string) => store.set(key, value),
+ removeItem: (key: string) => store.delete(key),
+ };
+ try {
+ run(store);
+ } finally {
+ (globalThis as { localStorage?: unknown }).localStorage = previous;
+ }
+}
+
+test("a minimized window is a degenerate box and a real one is not", () => {
+ assert.equal(isDegenerateBox({ width: 0, height: 0 }), true);
+ assert.equal(isDegenerateBox({ width: 1200, height: 0 }), true);
+ assert.equal(isDegenerateBox({ width: 0, height: 800 }), true);
+ assert.equal(isDegenerateBox({ width: 1, height: 1 }), false);
+ assert.equal(isDegenerateBox({ width: 1440, height: 900 }), false);
+});
+
+test("an undragged axis stays anchored to the far edge", () => {
+ assert.equal(placeAxis(null, 900), 900);
+ assert.equal(placeAxis(null, 0), 0);
+});
+
+test("a shrink clamps the painted spot and growing back restores it", () => {
+ const intent = 1100;
+ const sizes = [1200, 600, 1200];
+ assert.deepEqual(
+ sizes.map((max) => placeAxis(intent, max)),
+ [1100, 600, 1100],
+ );
+});
+
+test("the card returns to its spot after a minimize and restore", () => {
+ const card = { width: 268, height: 160 };
+ const chosen = { left: 900, top: 500 };
+ const big = { width: 1440, height: 900 };
+ const minimized = clampToViewport(chosen, card.width, card.height, { width: 0, height: 0 });
+ assert.deepEqual(minimized, { left: 8, top: 8 });
+ assert.deepEqual(clampToViewport(minimized, card.width, card.height, big), { left: 8, top: 8 });
+ assert.deepEqual(clampToViewport(chosen, card.width, card.height, big), chosen);
+});
+
+test("a dropped spot round-trips through storage, anchors included", () => {
+ withStorage(() => {
+ const key = FLOATING_PANEL_POSITION_KEYS.liveMonitor;
+ assert.equal(readPanelIntent(key), null);
+ storePanelIntent(key, { left: 420, top: null });
+ assert.deepEqual(readPanelIntent(key), { left: 420, top: null });
+ storePanelIntent(key, { left: 12.5, top: 300 });
+ assert.deepEqual(readPanelIntent(key), { left: 12.5, top: 300 });
+ });
+});
+
+test("a corrupt stored spot falls back to the default placement", () => {
+ withStorage((store) => {
+ const key = FLOATING_PANEL_POSITION_KEYS.apiMonitor;
+ for (const raw of ["{", "null", "[]", '{"left":"5","top":1}', '{"left":1}', '{"left":1e999,"top":1}']) {
+ store.set(key, raw);
+ assert.equal(readPanelIntent(key), null, raw);
+ }
+ assert.equal(readPanelIntent(undefined), null);
+ });
+});
+
+test("both monitors persist under their own key and a reset clears them", () => {
+ assert.match(
+ readSrc("components/floating-monitor.tsx"),
+ /FLOATING_PANEL_POSITION_KEYS\.liveMonitor,\s*\);/,
+ );
+ assert.match(
+ readSrc("features/api-monitor/api-monitor-overlay.tsx"),
+ /FLOATING_PANEL_POSITION_KEYS\.apiMonitor,\s*\);/,
+ );
+ assert.match(
+ readSrc("features/settings/tabs/general-tab.tsx"),
+ /\.\.\.Object\.values\(FLOATING_PANEL_POSITION_KEYS\),/,
+ );
+});
+
+test("layout skips a 0x0 frame and only a drag writes the stored spot", () => {
+ const hook = readSrc("hooks/use-floating-panel-layout.ts");
+ assert.match(hook, /if \(isDegenerateBox\(constraintsBox\)\) \{\s*return;/);
+ assert.equal(hook.split("storePanelIntent(").length - 1, 1);
+ const finish = hook.slice(hook.indexOf("function finishDrag"));
+ assert.match(finish, /storePanelIntent\(storageKey, intentRef\.current\)/);
+ const card = readSrc("features/loaded-models/use-drag-position.ts");
+ assert.match(card, /if \(isDegenerateBox\(view\)\) return;/);
+});
diff --git a/studio/frontend/tests/general-settings-token-sync.test.ts b/studio/frontend/tests/general-settings-token-sync.test.ts
index 3f03b330fbd..c8cf788f68c 100644
--- a/studio/frontend/tests/general-settings-token-sync.test.ts
+++ b/studio/frontend/tests/general-settings-token-sync.test.ts
@@ -135,6 +135,7 @@ function generalTab(initialToken: string) {
emitTrainingRunsChanged: noop,
TRAINING_UI_PREFERENCE_KEYS: [],
},
+ "@/hooks/floating-panel-position": { FLOATING_PANEL_POSITION_KEYS: {} },
"@/hooks/use-notification-frequency": notificationPrefStub,
"@/hooks": {
useHfTokenValidation: () => ({
diff --git a/studio/frontend/tests/loaded-models-drag-restore.test.ts b/studio/frontend/tests/loaded-models-drag-restore.test.ts
index 1c48c761494..344692379c3 100644
--- a/studio/frontend/tests/loaded-models-drag-restore.test.ts
+++ b/studio/frontend/tests/loaded-models-drag-restore.test.ts
@@ -90,14 +90,19 @@ test("clamping is idempotent, so the observer cannot feed itself", () => {
// ── The wiring the geometry depends on ──────────────────────────────────
-test("the stored position is clamped as it is read", () => {
+test("the stored position is clamped before the first measurement", () => {
// Without this the card paints once at the stored coordinates. On a smaller
// screen that single frame is off screen, and if the observer ever fails to
// attach it stays there.
assert.match(
SOURCE,
- /const stored = readStored[\s\S]{0,500}?clampToViewport\(stored,/,
- "useState initialiser must clamp what it reads",
+ /readStored\(storageKey\)[\s\S]{0,600}?width: 0,\s*height: 0,/,
+ "the fit starts at zero size so the read is clamped before any measurement",
+ );
+ assert.match(
+ SOURCE,
+ /clampToViewport\(chosen, fit\.width, fit\.height, fit\.viewport\)/,
+ "what is painted is always the clamped spot",
);
});