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: give a resize drag its cursor and hit test from an overlay, not the whole document (#9598)

Daniel Han9de32660d836
diff --git a/studio/frontend/src/components/ui/panel-resize-handle.tsx b/studio/frontend/src/components/ui/panel-resize-handle.tsx
index 6b0b558a161..1f8648f4ec3 100644
--- a/studio/frontend/src/components/ui/panel-resize-handle.tsx
+++ b/studio/frontend/src/components/ui/panel-resize-handle.tsx
@@ -13,6 +13,7 @@ import {
} from "@/components/ui/tooltip"
import { getClientPlatform } from "@/components/tauri/window-titlebar"
import { PANEL_RESIZE_SCOPED_VARS_ENABLED } from "@/components/ui/panel-resize-recalc-flags"
+import { Z_LAYER } from "@/lib/z-layers"
/** Pointer travel (px) below which a drag counts as a plain click. */
const DRAG_SLOP = 4
@@ -21,6 +22,68 @@ const CLICK_COMPAT_WINDOW_MS = 300
/** Arrow-key resize step for keyboard users. */
const RESIZE_STEP = 16
+// A drag needs one cursor over the whole viewport, because the pointer travels
+// across buttons and text that would otherwise claim their own. That used to be
+// `html[data-panel-resizing] *` plus `cursor`/`user-select` on <body>. Both
+// reach every element in the document: the universal selector matches all of
+// them, and `cursor` and `user-select` are inherited, so writing them on <body>
+// marks inherited style dirty for everything below it. The cost is therefore
+// proportional to the STANDING DOM rather than to the one thing that changed,
+// which is the same shape as the sidebar-width writes scoped in #9400/#9441.
+//
+// The same is true of the rule that blanked pointer events on the sidebar and
+// on [data-slot="sidebar-inset"], the <main> holding the whole app including
+// the thread: `pointer-events` is inherited too, so that write dirtied the
+// thread's subtree on both flips as well.
+//
+// A single fixed element on top of the viewport does both jobs with an
+// invalidation set of one element. It carries the cursor, and by being the hit
+// test target for the whole viewport it keeps hover and click off the content
+// underneath. It is transparent and it is removed the instant the drag ends, so
+// nothing about what the user sees changes.
+const DRAG_OVERLAY_SLOT = "panel-resize-drag-overlay"
+/** Nested drags cannot happen through pointer capture, but a stuck overlay would
+ * swallow the whole UI, so ownership is explicit rather than assumed. */
+let dragOverlayOwners = 0
+
+function acquireDragOverlay(): void {
+ dragOverlayOwners += 1
+ if (dragOverlayOwners > 1) return
+ const el = document.createElement("div")
+ el.setAttribute("data-slot", DRAG_OVERLAY_SLOT)
+ // Decorative and non-interactive as far as assistive tech is concerned: it
+ // exists only to own the cursor while the pointer is already captured.
+ el.setAttribute("aria-hidden", "true")
+ const s = el.style
+ s.position = "fixed"
+ s.inset = "0"
+ // Top of the named scale, not a hand-picked large number: the rules it
+ // replaces were `!important` and blanked whole subtrees, so anything it did
+ // not out-rank it would only partly stand in for.
+ s.zIndex = String(Z_LAYER.DRAG_CURSOR_OVERLAY)
+ s.background = "transparent"
+ // Explicit, because it is load-bearing rather than incidental. Being the hit
+ // test target for the whole viewport is what keeps hover and click off the
+ // content underneath, which is the job `pointer-events: none` on
+ // [data-slot="sidebar-inset"] used to do by dirtying the thread's subtree.
+ s.pointerEvents = "auto"
+ // col-resize unconditionally, which is what the replaced rule did even when a
+ // collapsed edge was being dragged open.
+ s.cursor = "col-resize"
+ s.userSelect = "none"
+ s.touchAction = "none"
+ document.body.appendChild(el)
+}
+
+function releaseDragOverlay(): void {
+ if (dragOverlayOwners === 0) return
+ dragOverlayOwners -= 1
+ if (dragOverlayOwners > 0) return
+ document
+ .querySelector(`[data-slot="${DRAG_OVERLAY_SLOT}"]`)
+ ?.remove()
+}
+
type DragState = {
startX: number
startWidth: number
@@ -130,6 +193,9 @@ export function PanelResizeHandle({
// Where `rootVar` is painted, resolved once on pointer down. Always
// [document.documentElement] with the flag off, which is what shipped.
const rootTargetsRef = React.useRef<HTMLElement[]>([])
+ // Whether THIS handle is holding the cursor overlay. endDrag also runs as the
+ // effect cleanup, where no drag happened and nothing was acquired.
+ const overlayHeldRef = React.useRef(false)
const paint = React.useCallback(
(value: string) => {
@@ -177,8 +243,10 @@ export function PanelResizeHandle({
document.documentElement.removeAttribute("data-panel-resizing")
targetRef.current = null
setDragging(false)
- document.body.style.removeProperty("cursor")
- document.body.style.removeProperty("user-select")
+ if (overlayHeldRef.current) {
+ overlayHeldRef.current = false
+ releaseDragOverlay()
+ }
}, [paint, rootVar])
const handlePointerDown = (event: React.PointerEvent<HTMLButtonElement>) => {
@@ -202,8 +270,8 @@ export function PanelResizeHandle({
targetRef.current?.setAttribute("data-resizing", "true")
document.documentElement.setAttribute("data-panel-resizing", "true")
setDragging(true)
- document.body.style.setProperty("cursor", "col-resize")
- document.body.style.setProperty("user-select", "none")
+ overlayHeldRef.current = true
+ acquireDragOverlay()
}
const handlePointerMove = (event: React.PointerEvent<HTMLButtonElement>) => {
diff --git a/studio/frontend/src/index.css b/studio/frontend/src/index.css
index f0b37af30b9..b81a857df6c 100644
--- a/studio/frontend/src/index.css
+++ b/studio/frontend/src/index.css
@@ -1605,22 +1605,12 @@ html[data-chat-font] .aui-root {
cursor: pointer;
}
- /* While a panel edge is dragged, keep the resize cursor even as the pointer
- travels over buttons and text that would claim their own. */
- html[data-panel-resizing],
- html[data-panel-resizing] * {
- cursor: col-resize !important;
- user-select: none !important;
- }
-
- html[data-panel-resizing]
- :is(
- [data-slot="sidebar-inner"],
- [data-slot="sidebar-inset"],
- [data-slot="chat-settings-panel"] > div
- ) {
- pointer-events: none;
- }
+ /* The resize cursor during a drag is owned by the fixed overlay that
+ PanelResizeHandle mounts for the life of the drag, not by a rule here.
+ A universal descendant selector on <html> restyles every element in the
+ document on each of the two attribute flips, which costs in proportion to
+ the standing DOM; the overlay costs one element. See
+ components/ui/panel-resize-handle.tsx. */
/* Model selector: pointer cursor on every clickable element. */
.unsloth-model-selector-trigger,
diff --git a/studio/frontend/src/lib/z-layers.ts b/studio/frontend/src/lib/z-layers.ts
index 2880af3574b..970a3e74ee9 100644
--- a/studio/frontend/src/lib/z-layers.ts
+++ b/studio/frontend/src/lib/z-layers.ts
@@ -16,6 +16,7 @@
* FLOATING_PANEL_TOP the one of those the user touched last
* STARTUP_SCREEN blocks the app while the backend comes up or quits
* TOOLTIP transient, must be readable above whatever spawned it
+ * DRAG_CURSOR_OVERLAY owns the cursor and the hit test during a panel drag
*
* In-page surfaces -- dropdowns, popovers, dialogs, sheets, the sidebar, the
* Tauri titlebar -- all sit in the 1..120 band on Tailwind's own `z-*` scale
@@ -49,6 +50,17 @@ export const Z_LAYER = {
STARTUP_SCREEN: 9999,
/** Tooltips, which have to be legible above whatever spawned them. */
TOOLTIP: 999999,
+ /**
+ * The transparent sheet PanelResizeHandle mounts for the life of a panel
+ * drag. Top of the scale because it owns two things for the whole viewport
+ * while it exists: the resize cursor, and the hit test. It replaces
+ * `html[data-panel-resizing] *`, which was `!important` and so beat every
+ * surface here, and the `pointer-events: none` rule that used to blank the
+ * sidebar and the main content; being above them is what makes it their
+ * equal rather than a partial stand-in. Transparent, and it exists only
+ * between pointerdown and pointerup, so nothing it covers is hidden.
+ */
+ DRAG_CURSOR_OVERLAY: 1000000,
} as const;
export type ZLayer = (typeof Z_LAYER)[keyof typeof Z_LAYER];
diff --git a/studio/frontend/tests/z-layers.test.ts b/studio/frontend/tests/z-layers.test.ts
index 75e71b476d5..61aefa40c27 100644
--- a/studio/frontend/tests/z-layers.test.ts
+++ b/studio/frontend/tests/z-layers.test.ts
@@ -18,6 +18,7 @@ const ORDER = [
"FLOATING_PANEL_TOP",
"STARTUP_SCREEN",
"TOOLTIP",
+ "DRAG_CURSOR_OVERLAY",
] as const;
test("the named layers are strictly ordered", () => {