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: stop WebKit restyling the whole page when dialogs, menus and the browser pane open or close (#16961)

Daniel Han9af15b95f728
diff --git a/studio/frontend/src/app/provider.tsx b/studio/frontend/src/app/provider.tsx
index dccfd2832c2..2929642e38a 100644
--- a/studio/frontend/src/app/provider.tsx
+++ b/studio/frontend/src/app/provider.tsx
@@ -1071,7 +1071,7 @@ function TauriWrapper({ children }: { children: ReactNode }) {
<div
data-tauri-drag-region={true}
aria-hidden="true"
- className="pointer-events-auto fixed inset-x-0 top-0 z-50 h-[var(--studio-mac-titlebar-height,34px)] select-none"
+ className="pointer-events-auto modal-pe-live fixed inset-x-0 top-0 z-50 h-[var(--studio-mac-titlebar-height,34px)] select-none"
/>
) : null}
{chromeVars}
diff --git a/studio/frontend/src/components/navbar.tsx b/studio/frontend/src/components/navbar.tsx
index 1ccca339215..7fa4dec00f0 100644
--- a/studio/frontend/src/components/navbar.tsx
+++ b/studio/frontend/src/components/navbar.tsx
@@ -18,7 +18,7 @@ export function Navbar() {
if (!isMobile) {
return (
<>
- <header className="pointer-events-none absolute inset-x-0 top-0 z-40 h-[calc(48px*var(--ui-space-scale,1))]">
+ <header className="modal-pe-live pointer-events-none absolute inset-x-0 top-0 z-40 h-[calc(48px*var(--ui-space-scale,1))]">
{usesNativeMacTitlebar && (
<div
data-tauri-drag-region
@@ -32,7 +32,7 @@ export function Navbar() {
<DesktopTitlebarNavigation
expanded={false}
onToggleSidebar={togglePinned}
- className="pointer-events-auto absolute left-[calc(var(--studio-mac-traffic-light-inset,78px)+calc(6px*var(--ui-space-scale,1)))] top-px z-[60]"
+ className="modal-pe-live pointer-events-auto absolute left-[calc(var(--studio-mac-traffic-light-inset,78px)+calc(6px*var(--ui-space-scale,1)))] top-px z-[60]"
/>
)}
</>
@@ -42,7 +42,7 @@ export function Navbar() {
return (
<header
className={cn(
- "absolute top-0 inset-x-0 pointer-events-none",
+ "modal-pe-live absolute top-0 inset-x-0 pointer-events-none",
usesCustomTitlebar
? "z-[80] h-[var(--studio-custom-titlebar-height,34px)]"
: "z-[45] h-[calc(48px*var(--ui-space-scale,1))]",
diff --git a/studio/frontend/src/components/tauri/startup-screen.tsx b/studio/frontend/src/components/tauri/startup-screen.tsx
index 926e70817be..f8d2565ea18 100644
--- a/studio/frontend/src/components/tauri/startup-screen.tsx
+++ b/studio/frontend/src/components/tauri/startup-screen.tsx
@@ -629,7 +629,7 @@ export function ClosingScreen() {
// would make this overlay click-through onto the hidden dialog.
<div
data-blocking-screen=""
- className="pointer-events-auto fixed inset-0 z-[9999]"
+ className="pointer-events-auto modal-pe-live fixed inset-0 z-[9999]"
>
<StartupSurface>
<div className="flex h-full w-full flex-col items-center justify-center text-center">
diff --git a/studio/frontend/src/components/tauri/update-screen.tsx b/studio/frontend/src/components/tauri/update-screen.tsx
index 945b9fc07aa..df6b11ef602 100644
--- a/studio/frontend/src/components/tauri/update-screen.tsx
+++ b/studio/frontend/src/components/tauri/update-screen.tsx
@@ -100,7 +100,7 @@ export function UpdateScreen({
<div
data-tauri-drag-region={true}
aria-hidden="true"
- className="pointer-events-auto fixed inset-x-0 top-0 z-50 h-[var(--studio-mac-titlebar-height,34px)] select-none"
+ className="pointer-events-auto modal-pe-live fixed inset-x-0 top-0 z-50 h-[var(--studio-mac-titlebar-height,34px)] select-none"
/>
)}
<div className="flex min-h-0 w-full max-w-md flex-1 items-center justify-center px-6">
diff --git a/studio/frontend/src/components/tauri/window-titlebar.tsx b/studio/frontend/src/components/tauri/window-titlebar.tsx
index 26af74ce965..7a7ec387796 100644
--- a/studio/frontend/src/components/tauri/window-titlebar.tsx
+++ b/studio/frontend/src/components/tauri/window-titlebar.tsx
@@ -503,7 +503,7 @@ export function WindowTitlebar({
)}
<header
className={cn(
- "pointer-events-none absolute inset-x-0 top-0 z-[70] h-[var(--studio-custom-titlebar-height)] select-none text-foreground",
+ "modal-pe-live pointer-events-none absolute inset-x-0 top-0 z-[70] h-[var(--studio-custom-titlebar-height)] select-none text-foreground",
showSidebarSurface && "bg-sidebar text-sidebar-foreground",
)}
data-titlebar-live-width-scope=""
@@ -578,38 +578,38 @@ export function WindowTitlebar({
<>
<div
aria-hidden="true"
- className="pointer-events-auto fixed inset-x-2 top-0 h-1 cursor-n-resize"
+ className="modal-pe-live pointer-events-auto fixed inset-x-2 top-0 h-1 cursor-n-resize"
style={{ zIndex: Z_LAYER.WINDOW_RESIZE_EDGE }}
onPointerDown={handleResizePointerDown("North")}
/>
{/* resize grips stay above dialogs and notifications. */}
<div
aria-hidden="true"
- className="pointer-events-auto fixed inset-x-2 bottom-0 h-1 cursor-s-resize"
+ className="modal-pe-live pointer-events-auto fixed inset-x-2 bottom-0 h-1 cursor-s-resize"
style={{ zIndex: Z_LAYER.WINDOW_RESIZE_EDGE }}
onPointerDown={handleResizePointerDown("South")}
/>
<div
aria-hidden="true"
- className="pointer-events-auto fixed inset-y-2 left-0 w-1 cursor-w-resize"
+ className="modal-pe-live pointer-events-auto fixed inset-y-2 left-0 w-1 cursor-w-resize"
style={{ zIndex: Z_LAYER.WINDOW_RESIZE_EDGE }}
onPointerDown={handleResizePointerDown("West")}
/>
<div
aria-hidden="true"
- className="pointer-events-auto fixed inset-y-2 right-0 w-1 cursor-e-resize"
+ className="modal-pe-live pointer-events-auto fixed inset-y-2 right-0 w-1 cursor-e-resize"
style={{ zIndex: Z_LAYER.WINDOW_RESIZE_EDGE }}
onPointerDown={handleResizePointerDown("East")}
/>
<div
aria-hidden="true"
- className="pointer-events-auto fixed left-0 top-0 size-3 cursor-nw-resize"
+ className="modal-pe-live pointer-events-auto fixed left-0 top-0 size-3 cursor-nw-resize"
style={{ zIndex: Z_LAYER.WINDOW_RESIZE_EDGE }}
onPointerDown={handleResizePointerDown("NorthWest")}
/>
<div
aria-hidden="true"
- className="pointer-events-auto fixed right-0 top-0 size-3 cursor-ne-resize"
+ className="modal-pe-live pointer-events-auto fixed right-0 top-0 size-3 cursor-ne-resize"
style={{
zIndex: Z_LAYER.WINDOW_RESIZE_EDGE,
// keep the resize corner outside the close button.
@@ -620,13 +620,13 @@ export function WindowTitlebar({
/>
<div
aria-hidden="true"
- className="pointer-events-auto fixed bottom-0 left-0 size-3 cursor-sw-resize"
+ className="modal-pe-live pointer-events-auto fixed bottom-0 left-0 size-3 cursor-sw-resize"
style={{ zIndex: Z_LAYER.WINDOW_RESIZE_EDGE }}
onPointerDown={handleResizePointerDown("SouthWest")}
/>
<div
aria-hidden="true"
- className="pointer-events-auto fixed bottom-0 right-0 size-3 cursor-se-resize"
+ className="modal-pe-live pointer-events-auto fixed bottom-0 right-0 size-3 cursor-se-resize"
style={{ zIndex: Z_LAYER.WINDOW_RESIZE_EDGE }}
onPointerDown={handleResizePointerDown("SouthEast")}
/>
diff --git a/studio/frontend/src/components/ui/combobox.tsx b/studio/frontend/src/components/ui/combobox.tsx
index 9650386cfda..7b9f5698597 100644
--- a/studio/frontend/src/components/ui/combobox.tsx
+++ b/studio/frontend/src/components/ui/combobox.tsx
@@ -169,7 +169,7 @@ function ComboboxContent({
anchor={anchor}
// Base UI's default padding is 5.
collisionPadding={useWindowChromeCollisionPadding(5)}
- className="isolate z-[120] pointer-events-auto"
+ className="isolate z-[120] modal-pe-live pointer-events-auto"
>
<ComboboxPrimitive.Popup
ref={snappedRef}
diff --git a/studio/frontend/src/components/ui/sonner.tsx b/studio/frontend/src/components/ui/sonner.tsx
index 3e2edae113f..eb8bdc49147 100644
--- a/studio/frontend/src/components/ui/sonner.tsx
+++ b/studio/frontend/src/components/ui/sonner.tsx
@@ -144,7 +144,7 @@ const Toaster = ({ ...props }: ToasterProps) => {
toastOptions={{
classNames: {
// an open modal dialog sets pointer-events:none on body, which toasts would otherwise inherit.
- toast: "cn-toast pointer-events-auto",
+ toast: "cn-toast modal-pe-live pointer-events-auto",
description: "!text-muted-foreground",
},
}}
diff --git a/studio/frontend/src/features/browser/browser-panel.tsx b/studio/frontend/src/features/browser/browser-panel.tsx
index 0b1efe720fb..67d0ad033f4 100644
--- a/studio/frontend/src/features/browser/browser-panel.tsx
+++ b/studio/frontend/src/features/browser/browser-panel.tsx
@@ -2537,7 +2537,7 @@ export const BrowserPanel = memo(function BrowserPanel({
}
}}
className={cn(
- "relative flex h-full min-h-0 flex-col overflow-hidden bg-muted",
+ "side-pane-lock-cover relative flex h-full min-h-0 flex-col overflow-hidden bg-muted",
floating ? "rounded-[inherit]" : "pt-[var(--studio-content-top-inset,0px)]",
documentShown
? "[--browser-surface:color-mix(in_oklab,var(--muted)_55%,var(--card))]"
diff --git a/studio/frontend/src/features/chat/components/research-activity-panel.tsx b/studio/frontend/src/features/chat/components/research-activity-panel.tsx
index 1301dadda0c..5c61a913f9d 100644
--- a/studio/frontend/src/features/chat/components/research-activity-panel.tsx
+++ b/studio/frontend/src/features/chat/components/research-activity-panel.tsx
@@ -884,6 +884,7 @@ export function ResearchActivityPanel({
className={cn(
"relative flex min-h-0 flex-col bg-background text-foreground",
variant === "sheet" && "h-full",
+ variant === "panel" && "side-pane-lock-cover",
)}
style={
variant === "panel"
diff --git a/studio/frontend/src/features/interface-zoom/components/interface-zoom.tsx b/studio/frontend/src/features/interface-zoom/components/interface-zoom.tsx
index 4448f007cff..7df35f04305 100644
--- a/studio/frontend/src/features/interface-zoom/components/interface-zoom.tsx
+++ b/studio/frontend/src/features/interface-zoom/components/interface-zoom.tsx
@@ -79,7 +79,7 @@ function ZoomPopup() {
return (
// pointer-events-auto survives a modal's body lock.
<div
- className="interface-zoom-position pointer-events-auto fixed right-4"
+ className="modal-pe-live interface-zoom-position pointer-events-auto fixed right-4"
style={{ zIndex: Z_LAYER.ZOOM_POPUP }}
// Keeps an open modal from treating this as an outside click.
onPointerDown={(event) => event.stopPropagation()}
diff --git a/studio/frontend/src/index.css b/studio/frontend/src/index.css
index ee6465f633c..fef3224fc12 100644
--- a/studio/frontend/src/index.css
+++ b/studio/frontend/src/index.css
@@ -2086,7 +2086,18 @@ html[data-chat-font] .aui-root {
overflow: hidden;
}
+ /* The modal scroll lock (src/lib/remove-scroll.tsx). Static, not the <style> react-remove-scroll-bar
+ injected per lock: removing that sheet on close rebuilt every style in WebKit (about 2.7 s at 100
+ turns). Same declarations, with the 0px gap the page always measured (it never scrolls). */
body[data-scroll-locked] {
+ overflow: hidden !important;
+ overscroll-behavior: contain;
+ position: relative !important;
+ padding-left: 0;
+ padding-top: 0;
+ padding-right: 0;
+ margin-left: 0;
+ margin-top: 0;
margin-right: 0 !important;
}
/* The 0px react-remove-scroll sets on modal open. Preset so the lock
@@ -2111,6 +2122,39 @@ html[data-chat-font] .aui-root {
z-index: 49;
pointer-events: auto;
}
+ /* The side pane (browser, research) sets its own pointer-events: auto once shown, so it never
+ inherited the lock and its scrollers (file view, page) took wheel and touch under a modal menu.
+ The same cover over it blocks them as react-remove-scroll's document listeners did, without a
+ listener per open (each add or remove restyles the whole page in WebKit). The pane roots carry a
+ static class, so the lock toggle only looks at them (an attribute or :is() subject here made
+ every toggle restyle the thread: 120 ms at 200 turns). Both roots are position: relative;
+ dialogs and menus portal to <body> at z-50, above the cover. Its own layer: Chromium's
+ compositor otherwise hit-tests the composited scroller under a paintless cover and scrolls it. */
+ body[style*="pointer-events: none"] .chat-artifact-pop-surface .side-pane-lock-cover::after {
+ content: "";
+ position: absolute;
+ inset: 0;
+ z-index: 49;
+ pointer-events: auto;
+ will-change: transform;
+ }
+ /* pointer-events-auto restorations (rows, toolbars) inside a dialog or menu that a nested modal
+ menu has made a lower layer (Radix writes pointer-events: none on it) stayed hit-testable, so
+ wheel over one scrolled the list behind the menu (Skills rows under Skill actions). Popper
+ content portaled into that dialog (a modal popover, a select) is the top layer, so it is left
+ alone. Class-keyed: a lock toggle only looks at these elements. */
+ :is([role="dialog"], [role="alertdialog"], [role="menu"], [role="listbox"])[style*="pointer-events: none"] .pointer-events-auto:not([data-radix-popper-content-wrapper] *) {
+ pointer-events: none !important;
+ }
+ /* The same for pointer-events-auto restorations in the page itself (toolbars, the Downloads card,
+ floating monitors): with the body lock on, wheel over one scrolled what sits behind the modal.
+ Left live: the top dialog (contained or portaled), every popper popup, the thread (its cover
+ blocks it, and its many restorations would restyle on each toggle) and window chrome, toasts and
+ overlays that are meant to work over a modal (.modal-pe-live). Sidebar row actions restore it in
+ CSS (an open disclosure arrow) rather than with the class. Class-keyed like the rule above. */
+ body[style*="pointer-events: none"] :is(.pointer-events-auto, .sidebar-row-action):not(.aui-thread-root *):not([role="dialog"] *):not([role="alertdialog"] *):not([data-radix-popper-content-wrapper] *):not(.modal-pe-live):not(.modal-pe-live *) {
+ pointer-events: none !important;
+ }
/* Firefox makes scrollable containers focusable; :where keeps specificity at zero. */
:where(div, main, section, aside, ul, ol):focus-visible {
diff --git a/studio/frontend/src/lib/closing-dialog-focus.ts b/studio/frontend/src/lib/closing-dialog-focus.ts
new file mode 100644
index 00000000000..f2e61c04ab2
--- /dev/null
+++ b/studio/frontend/src/lib/closing-dialog-focus.ts
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+/**
+ * A closing dialog keeps focus inside it until it unmounts after its exit animation. In WebKit that
+ * exit, with the focused element still in the fading dialog, ends in one long restyle of the whole
+ * page: about 2 s on a 100-turn chat when Settings, the command palette, search or rename closes.
+ * Blurring as the exit animation starts avoids it. Radix still returns focus to the trigger when the
+ * dialog unmounts, so where focus lands afterwards is unchanged. Chromium never paid this.
+ */
+
+type ClosingTarget = {
+ getAttribute(name: string): string | null;
+ matches(selector: string): boolean;
+ contains(other: unknown): boolean;
+};
+
+type Focusable = { blur(): void };
+
+const DIALOG = '[role="dialog"], [role="alertdialog"]';
+
+/** True when `target` is a dialog in its closing state that holds `active`, which was then blurred. */
+export function blurInsideClosingDialog(
+ target: ClosingTarget | null,
+ active: Focusable | null,
+): boolean {
+ if (!target || !active || target.getAttribute("data-state") !== "closed") return false;
+ if (!target.matches(DIALOG) || !target.contains(active)) return false;
+ active.blur();
+ return true;
+}
+
+function onAnimationStart(event: Event): void {
+ const target = event.target;
+ if (!(target instanceof Element)) return;
+ const active = target.ownerDocument.activeElement;
+ blurInsideClosingDialog(target, active instanceof HTMLElement ? active : null);
+}
+
+/** Idempotent: one capture listener per document. */
+export function watchClosingDialogFocus(doc: Document): void {
+ doc.addEventListener("animationstart", onAnimationStart, true);
+}
diff --git a/studio/frontend/src/lib/pointer-listener-pin.ts b/studio/frontend/src/lib/pointer-listener-pin.ts
new file mode 100644
index 00000000000..92e4c453a20
--- /dev/null
+++ b/studio/frontend/src/lib/pointer-listener-pin.ts
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+/**
+ * WebKit folds window and document pointer listeners into the style of every element (event listener
+ * regions), so the first listener of a type added there, or the last one removed, restyles the whole
+ * page. react-resizable-panels adds and removes its document pointer listeners each time a panel group
+ * re-registers, which the browser pane does several times while it opens and closes: about 2 s per
+ * step on a 100-turn chat. One no-op listener of each type held for the page's lifetime keeps that set
+ * constant, so those adds and removes change nothing. Chromium is unaffected either way.
+ */
+
+export const PINNED_POINTER_EVENTS = [
+ "pointerdown",
+ "pointermove",
+ "pointerup",
+ "pointercancel",
+ "pointerover",
+ "pointerout",
+ "pointerenter",
+ "pointerleave",
+] as const;
+
+function keepRegion(): void {}
+
+/** Idempotent: the same listener is only ever registered once per type. */
+export function pinPointerListenerRegions(
+ target: Pick<EventTarget, "addEventListener">,
+): void {
+ for (const type of PINNED_POINTER_EVENTS) target.addEventListener(type, keepRegion);
+}
diff --git a/studio/frontend/src/lib/remove-scroll.tsx b/studio/frontend/src/lib/remove-scroll.tsx
new file mode 100644
index 00000000000..43416ad27d4
--- /dev/null
+++ b/studio/frontend/src/lib/remove-scroll.tsx
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+/**
+ * Stands in for `react-remove-scroll` (aliased in vite.config.ts), the scroll lock Radix dialogs, modal
+ * menus, selects and modal popovers mount while open.
+ *
+ * WebKit folds window and document wheel / touch listeners into the style of every element (event
+ * listener regions), so the library's non-passive document listeners restyled the whole page on each
+ * open and again on close: about 2.5 s per step on a 100-turn chat. Removing its injected <style> on
+ * close rebuilt every style once more. Chromium pays neither.
+ *
+ * What the lock did here is kept: the `data-scroll-locked` counter on <body>, with the styles the
+ * library injected now static in index.css. Its wheel and touch cancelling is dropped: under a modal
+ * layer nothing outside it can be wheel-scrolled anyway (body is `pointer-events: none`, the thread
+ * sits under a cover, the page itself never scrolls), and lists inside dialogs already scroll on
+ * their own (`useWheelScrollRef`, popovers portaled into the dialog).
+ */
+
+import { forwardRef, type ReactElement, useEffect } from "react";
+import type { IRemoveScrollProps } from "react-remove-scroll/dist/es2015/types";
+import { RemoveScroll as RemoveScrollUI } from "react-remove-scroll/UI";
+
+const LOCK_ATTRIBUTE = "data-scroll-locked";
+
+/** Same counter as react-remove-scroll-bar, so nested and mixed locks agree on when it ends. */
+function lockCount(): number {
+ const count = Number.parseInt(document.body.getAttribute(LOCK_ATTRIBUTE) || "0", 10);
+ return Number.isFinite(count) ? count : 0;
+}
+
+function ScrollLockSideCar({ removeScrollBar }: { removeScrollBar?: boolean }): ReactElement | null {
+ useEffect(() => {
+ if (removeScrollBar === false) return;
+ document.body.setAttribute(LOCK_ATTRIBUTE, String(lockCount() + 1));
+ return () => {
+ const next = lockCount() - 1;
+ if (next <= 0) document.body.removeAttribute(LOCK_ATTRIBUTE);
+ else document.body.setAttribute(LOCK_ATTRIBUTE, String(next));
+ };
+ }, [removeScrollBar]);
+ return null;
+}
+
+// The library's defaults, spelled out: JSX does not apply its `defaultProps` (React 19), and Radix
+// passes none of these, so without them the lock would never engage.
+const RemoveScrollLock = forwardRef<HTMLElement, IRemoveScrollProps>(function RemoveScroll(
+ { enabled = true, removeScrollBar = true, inert = false, ...props },
+ ref,
+) {
+ return (
+ <RemoveScrollUI
+ {...props}
+ enabled={enabled}
+ removeScrollBar={removeScrollBar}
+ inert={inert}
+ ref={ref}
+ sideCar={ScrollLockSideCar}
+ />
+ );
+});
+
+export const RemoveScroll = Object.assign(RemoveScrollLock, {
+ classNames: RemoveScrollUI.classNames,
+});
+
+export default RemoveScroll;
diff --git a/studio/frontend/src/main.tsx b/studio/frontend/src/main.tsx
index c684ff31bc2..35e749feb3a 100644
--- a/studio/frontend/src/main.tsx
+++ b/studio/frontend/src/main.tsx
@@ -34,10 +34,12 @@ import {
import { initializeLocale } from "./i18n";
import { isTauri } from "./lib/api-base";
import { markAppSessionStart } from "./lib/app-session-start";
+import { watchClosingDialogFocus } from "./lib/closing-dialog-focus";
import { setHubSessionRefresh } from "./lib/hf-endpoint";
import { watchInputModality } from "./lib/input-modality";
import { watchMacStrayKeyText } from "./lib/mac-stray-key-text";
import { watchOverlayScrollbarGutter } from "./lib/overlay-scrollbar";
+import { pinPointerListenerRegions } from "./lib/pointer-listener-pin";
import { watchSpellCheck } from "./lib/spellcheck";
import { watchTimeFormat } from "./lib/time-format";
@@ -83,6 +85,9 @@ watchReasoningRowContainmentOverride();
watchOverlayScrollbarGutter(window);
watchInputModality(window);
+// Before any panel group mounts: their document pointer listeners then never change WebKit's page-wide set.
+pinPointerListenerRegions(document);
+watchClosingDialogFocus(document);
watchSpellCheck(window);
watchTimeFormat(window);
diff --git a/studio/frontend/tests/interface-zoom.test.ts b/studio/frontend/tests/interface-zoom.test.ts
index d0dab264367..8b8b76fad61 100644
--- a/studio/frontend/tests/interface-zoom.test.ts
+++ b/studio/frontend/tests/interface-zoom.test.ts
@@ -251,7 +251,7 @@ test("the zoom popup takes the find bar's corner", () => {
assert.match(provider, /data-blocking-screen=""\s*className="fixed inset-0 z-40 bg-background"/);
assert.match(
readSrc("components/tauri/startup-screen.tsx"),
- /data-blocking-screen=""\s*className="pointer-events-auto fixed inset-0 z-\[9999\]"/,
+ /data-blocking-screen=""\s*className="pointer-events-auto modal-pe-live fixed inset-0 z-\[9999\]"/,
);
assert.match(
readSrc("features/interface-zoom/components/interface-zoom.tsx"),
diff --git a/studio/frontend/tests/webkit-modal-page-restyle.test.ts b/studio/frontend/tests/webkit-modal-page-restyle.test.ts
new file mode 100644
index 00000000000..a2a4334cb61
--- /dev/null
+++ b/studio/frontend/tests/webkit-modal-page-restyle.test.ts
@@ -0,0 +1,150 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+/**
+ * WebKit restyles the whole page (about 2-2.5 s each on a 100-turn chat) when a window or document
+ * wheel / touch / pointer listener set changes, when a <style> is removed, and when a dialog exits
+ * with focus inside it. These pin the guards that keep modal layers and the browser pane off those paths.
+ */
+
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import { blurInsideClosingDialog } from "../src/lib/closing-dialog-focus.ts";
+import {
+ PINNED_POINTER_EVENTS,
+ pinPointerListenerRegions,
+} from "../src/lib/pointer-listener-pin.ts";
+import { readSrc, readText } from "./helpers/kit.ts";
+
+function rule(css: string, selector: string): string {
+ const at = css.indexOf(`${selector} {`);
+ assert.ok(at >= 0, `missing rule ${selector}`);
+ return css.slice(at, css.indexOf("}", at) + 1);
+}
+
+test("react-remove-scroll resolves to the listener-free scroll lock, and only the bare specifier", () => {
+ const config = readText("../vite.config.ts");
+ assert.match(
+ config,
+ /find: \/\^react-remove-scroll\$\/,\s*replacement: path\.resolve\(__dirname, "\.\/src\/lib\/remove-scroll\.tsx"\)/,
+ );
+ // The stand-in imports the library's own UI half, which an unanchored alias would swallow.
+ assert.match(readSrc("lib/remove-scroll.tsx"), /from "react-remove-scroll\/UI"/);
+});
+
+test("the scroll lock keeps the body counter and adds no listeners or stylesheets", () => {
+ const source = readSrc("lib/remove-scroll.tsx").replace(/\/\*[\s\S]*?\*\//g, "");
+ assert.match(source, /data-scroll-locked/);
+ assert.doesNotMatch(source, /addEventListener|createElement\(|<style|styleSingleton/);
+ assert.match(source, /export const RemoveScroll\b/);
+ // JSX skips the library's defaultProps, so the defaults Radix relies on are explicit.
+ assert.match(source, /enabled = true, removeScrollBar = true, inert = false/);
+ assert.match(source, /classNames: RemoveScrollUI\.classNames/);
+});
+
+test("the lock's body styles are static, with what react-remove-scroll-bar injected", () => {
+ const lock = rule(readSrc("index.css"), "body[data-scroll-locked]");
+ for (const declaration of [
+ "overflow: hidden !important;",
+ "overscroll-behavior: contain;",
+ "position: relative !important;",
+ "margin-right: 0 !important;",
+ ]) {
+ assert.ok(lock.includes(declaration), `body[data-scroll-locked] lost ${declaration}`);
+ }
+});
+
+test("document pointer listeners are pinned once per type, before the app mounts", () => {
+ const added: [string, unknown][] = [];
+ const target = {
+ addEventListener(type: string, listener: unknown) {
+ added.push([type, listener]);
+ },
+ };
+ pinPointerListenerRegions(target);
+ pinPointerListenerRegions(target);
+ assert.deepEqual(
+ [...new Set(added.map(([type]) => type))].sort(),
+ [...PINNED_POINTER_EVENTS].sort(),
+ );
+ // One shared function, so the browser dedupes repeated calls.
+ assert.equal(new Set(added.map(([, listener]) => listener)).size, 1);
+ // The types react-resizable-panels adds and removes on the document.
+ for (const type of ["pointermove", "pointerleave", "pointerout", "pointerdown", "pointerup"]) {
+ assert.ok((PINNED_POINTER_EVENTS as readonly string[]).includes(type), type);
+ }
+ const main = readSrc("main.tsx");
+ assert.match(main, /pinPointerListenerRegions\(document\);/);
+ assert.ok(main.indexOf("pinPointerListenerRegions(document)") < main.indexOf("root.render("));
+});
+
+function dialog(state: string, role = "dialog", holds = true) {
+ return {
+ getAttribute: (name: string) => (name === "data-state" ? state : null),
+ matches: (selector: string) => selector.includes(`[role="${role}"]`),
+ contains: () => holds,
+ };
+}
+
+test("a closing dialog gives up focus when its exit animation starts", () => {
+ let blurred = 0;
+ const active = { blur: () => void blurred++ };
+ assert.equal(blurInsideClosingDialog(dialog("closed"), active), true);
+ assert.equal(blurInsideClosingDialog(dialog("closed", "alertdialog"), active), true);
+ assert.equal(blurred, 2);
+ // Opening dialogs, other closing layers, and focus elsewhere are left alone.
+ assert.equal(blurInsideClosingDialog(dialog("open"), active), false);
+ assert.equal(blurInsideClosingDialog(dialog("closed", "menu"), active), false);
+ assert.equal(blurInsideClosingDialog(dialog("closed", "dialog", false), active), false);
+ assert.equal(blurInsideClosingDialog(null, active), false);
+ assert.equal(blurInsideClosingDialog(dialog("closed"), null), false);
+ assert.equal(blurred, 2);
+ assert.match(readSrc("main.tsx"), /watchClosingDialogFocus\(document\);/);
+});
+
+test("the side pane sits under the same modal cover as the thread", () => {
+ const css = readSrc("index.css");
+ const selector =
+ 'body[style*="pointer-events: none"] .chat-artifact-pop-surface .side-pane-lock-cover::after';
+ const cover = rule(css, selector);
+ // will-change: its own layer, or Chromium's compositor scrolls the pane's scroller under it.
+ for (const declaration of ['content: "";', "position: absolute;", "inset: 0;", "pointer-events: auto;", "will-change: transform;"]) {
+ assert.ok(cover.includes(declaration), `side pane cover lost ${declaration}`);
+ }
+ const z = Number(/z-index: (\d+);/.exec(cover)?.[1]);
+ assert.ok(z > 0 && z < 50, `cover z-index ${z} must sit under the z-50 portaled layers`);
+ // The shown pane opts out of the body lock, which is why it needs the cover.
+ assert.match(rule(css, '.chat-artifact-pop-surface[data-artifact-surface-visible="true"]'), /pointer-events: auto;/);
+ // Keyed on a static class on the pane roots, which also position the cover: an attribute or :is()
+ // subject here made every lock toggle restyle the thread (gate: 120 ms at 200 turns).
+ assert.match(readSrc("features/browser/browser-panel.tsx"), /"side-pane-lock-cover relative flex h-full min-h-0 flex-col overflow-hidden/);
+ assert.match(readSrc("features/chat/components/research-activity-panel.tsx"), /"relative flex min-h-0 flex-col[\s\S]{0,120}variant === "panel" && "side-pane-lock-cover"/);
+});
+
+test("pointer-events-auto restorations go inert in a lower modal layer, not in the page", () => {
+ const css = readSrc("index.css");
+ const lower =
+ ':is([role="dialog"], [role="alertdialog"], [role="menu"], [role="listbox"])[style*="pointer-events: none"] .pointer-events-auto:not([data-radix-popper-content-wrapper] *)';
+ assert.match(rule(css, lower), /pointer-events: none !important;/);
+ // The Skills rows (the confirmed case) restore pointer-events with exactly this class.
+ assert.match(readSrc("features/chat/components/chat-skills-dialog.tsx"), /className="pointer-events-auto absolute inset-0/);
+ // No page-wide rule: dialogs portaled into the page (Recipe Studio) host live comboboxes there.
+ assert.doesNotMatch(css, /\[data-slot="sidebar-inset"\] \.pointer-events-auto/);
+ // Page restorations (toolbars, the Downloads card) go inert under the body lock, with one rule.
+ const page =
+ 'body[style*="pointer-events: none"] :is(.pointer-events-auto, .sidebar-row-action):not(.aui-thread-root *):not([role="dialog"] *):not([role="alertdialog"] *):not([data-radix-popper-content-wrapper] *):not(.modal-pe-live):not(.modal-pe-live *)';
+ assert.match(rule(css, page), /pointer-events: none !important;/);
+ assert.match(readSrc("features/hub/download-manager/download-manager-panel.tsx"), /"hub-download-panel pointer-events-auto /);
+ // What is meant to work over a modal stays live.
+ const live: Array<[string, RegExp]> = [
+ ["components/tauri/window-titlebar.tsx", /"modal-pe-live pointer-events-none absolute inset-x-0 top-0 z-\[70\]/],
+ ["components/tauri/startup-screen.tsx", /"pointer-events-auto modal-pe-live fixed inset-0 z-\[9999\]"/],
+ ["components/ui/sonner.tsx", /toast: "cn-toast modal-pe-live pointer-events-auto"/],
+ ["components/ui/combobox.tsx", /"isolate z-\[120\] modal-pe-live pointer-events-auto"/],
+ ["features/interface-zoom/components/interface-zoom.tsx", /"modal-pe-live interface-zoom-position pointer-events-auto/],
+ ["app/provider.tsx", /data-tauri-drag-region=\{true\}[\s\S]{0,80}"pointer-events-auto modal-pe-live /],
+ ];
+ for (const [file, re] of live) assert.match(readSrc(file), re, file);
+ assert.equal(readSrc("components/tauri/window-titlebar.tsx").match(/"pointer-events-auto fixed /g), null);
+});
diff --git a/studio/frontend/vite.config.ts b/studio/frontend/vite.config.ts
index 6f7d5e0723d..dbe47313e26 100644
--- a/studio/frontend/vite.config.ts
+++ b/studio/frontend/vite.config.ts
@@ -43,7 +43,10 @@ export default defineConfig({
},
},
optimizeDeps: {
- include: ["@dagrejs/dagre", "@dagrejs/graphlib"],
+ // react-remove-scroll/UI is only imported by the aliased stand-in (src/lib/remove-scroll.tsx),
+ // which the dev server's first scan does not see; found later, it forces a re-optimize and a
+ // full reload that native Safari does not recover from.
+ include: ["@dagrejs/dagre", "@dagrejs/graphlib", "react-remove-scroll/UI"],
},
server: {
host: "0.0.0.0",
@@ -85,13 +88,22 @@ export default defineConfig({
},
},
resolve: {
- alias: {
- "@": path.resolve(__dirname, "./src"),
- "@dagrejs/dagre": path.resolve(
- __dirname,
- "./node_modules/@dagrejs/dagre/dist/dagre.cjs.js",
- ),
- },
+ alias: [
+ { find: "@", replacement: path.resolve(__dirname, "./src") },
+ {
+ find: "@dagrejs/dagre",
+ replacement: path.resolve(
+ __dirname,
+ "./node_modules/@dagrejs/dagre/dist/dagre.cjs.js",
+ ),
+ },
+ // Radix's scroll lock without its document wheel / touch listeners, which restyle the
+ // whole page in WebKit on every modal open and close (src/lib/remove-scroll.tsx).
+ {
+ find: /^react-remove-scroll$/,
+ replacement: path.resolve(__dirname, "./src/lib/remove-scroll.tsx"),
+ },
+ ],
},
build: {
commonjsOptions: {