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 dialogs and menus from restyling the whole chat on open and close (#16902)

Daniel Han3738b40e4334
diff --git a/studio/frontend/src/index.css b/studio/frontend/src/index.css
index 32eee5a9baf..b4ab57ebe36 100644
--- a/studio/frontend/src/index.css
+++ b/studio/frontend/src/index.css
@@ -2095,6 +2095,23 @@ html[data-chat-font] .aui-root {
--removed-body-scroll-bar-size: 0px;
}
+ /* Radix modal layers (dialogs, modal menus, selects) write pointer-events: none on <body>.
+ That property is inherited, so every open and close restyled each element of the chat:
+ about 40k elements at 100 turns, 0.45 s in Chromium and 2.4 s in WebKit per toggle. An
+ explicit value on the scroller stops the inheritance there, and while the lock is up a
+ transparent cover keeps the thread unclickable and unhovered exactly as before. Portaled
+ layers (z-50) stay above the cover. */
+ :where(.aui-thread-viewport) {
+ pointer-events: auto;
+ }
+ body[style*="pointer-events: none"] .aui-thread-root::after {
+ content: "";
+ position: absolute;
+ inset: 0;
+ z-index: 49;
+ pointer-events: auto;
+ }
+
/* Firefox makes scrollable containers focusable; :where keeps specificity at zero. */
:where(div, main, section, aside, ul, ol):focus-visible {
outline: 1px solid var(--ring-soft);
diff --git a/studio/frontend/tests/modal-lock-thread-cover.test.ts b/studio/frontend/tests/modal-lock-thread-cover.test.ts
new file mode 100644
index 00000000000..777005f49ff
--- /dev/null
+++ b/studio/frontend/tests/modal-lock-thread-cover.test.ts
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import { readSrc } from "./helpers/kit.ts";
+
+const CSS = readSrc("index.css");
+
+function rule(selector: string): string {
+ const at = CSS.indexOf(`${selector} {`);
+ assert.ok(at >= 0, `missing rule ${selector}`);
+ return CSS.slice(at, CSS.indexOf("}", at) + 1);
+}
+
+test("the thread scroller does not inherit a modal layer's body pointer-events lock", () => {
+ // Radix writes pointer-events: none on <body> for dialogs and modal menus. Inherited, it
+ // restyled every message on each open and close; an explicit value stops it at the scroller.
+ // Zero specificity: any deliberate pointer-events rule on the scroller still wins.
+ assert.match(rule(":where(.aui-thread-viewport)"), /pointer-events: auto;/);
+});
+
+test("while the lock is up a cover keeps the thread unclickable, below portaled layers", () => {
+ const cover = rule('body[style*="pointer-events: none"] .aui-thread-root::after');
+ assert.match(cover, /content: "";/);
+ assert.match(cover, /position: absolute;/);
+ assert.match(cover, /inset: 0;/);
+ // Its own value: it would otherwise inherit none from the locked body and let clicks through.
+ assert.match(cover, /pointer-events: auto;/);
+ // Below the z-50 dialogs, menus and popovers that Radix portals to <body>.
+ 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 root positions the cover, and no other rule draws on its ::after.
+ assert.match(
+ readSrc("components/assistant-ui/thread.tsx"),
+ /className="aui-root aui-thread-root relative /,
+ );
+ assert.equal(CSS.split(".aui-thread-root::after").length - 1, 1);
+});
diff --git a/tests/studio/playwright_long_thread_gate.py b/tests/studio/playwright_long_thread_gate.py
index f3d8be9dd5f..ab556c3e471 100644
--- a/tests/studio/playwright_long_thread_gate.py
+++ b/tests/studio/playwright_long_thread_gate.py
@@ -52,6 +52,11 @@ LARGE = int(os.environ.get("LONG_THREAD_LARGE", "200"))
# 423-472 ms (5.3-6.0x) and :has() 74-84 ms; healthy, 0.7-0.9 -> 0.7-1.0 ms (1.00x) and 0.2 ms.
MAX_MATCH_RATIO = float(os.environ.get("LONG_THREAD_MAX_MATCH_RATIO", "2.0"))
MAX_HAS_MS = float(os.environ.get("LONG_THREAD_MAX_HAS_MS", "5.0"))
+# Style recalc for one open or close of a modal layer (Radix writes pointer-events: none on <body>,
+# an inherited property). Healthy: 1-5 ms at 200 turns; when the thread inherits it, every message
+# restyles and this is hundreds of ms in Chromium and seconds in WebKit.
+MAX_LOCK_MS = float(os.environ.get("LONG_THREAD_MAX_LOCK_MS", "30.0"))
+LOCK_TOGGLES = 4
# A ratio inside this band gets a second interleaved repeat before the verdict; outside it, one
# measurement is decisive (healthy runs read 1.00x, the regression 5.3-6.0x).
RECHECK_BAND = (1.5, 3.0)
@@ -191,6 +196,23 @@ def style_per_key(cdp, page, keys: str) -> float:
return 1000 * (metrics(cdp)["RecalcStyleDuration"] - m0["RecalcStyleDuration"]) / len(keys)
+def lock_style_ms(cdp, page) -> float:
+ """Untraced style recalc per open/close of a modal layer's body pointer-events lock."""
+ m0 = metrics(cdp)
+ for _ in range(LOCK_TOGGLES):
+ for value in ("none", ""):
+ page.evaluate(
+ "(v) => { document.body.style.pointerEvents = v; return getComputedStyle(document.body).color; }",
+ value,
+ )
+ page.wait_for_timeout(30)
+ return (
+ 1000
+ * (metrics(cdp)["RecalcStyleDuration"] - m0["RecalcStyleDuration"])
+ / (2 * LOCK_TOGGLES)
+ )
+
+
def measure(browser, base: str, turns: int) -> dict:
ctx, page, cdp = open_thread(browser, base, turns)
shape = page.evaluate("""() => ({
@@ -250,6 +272,7 @@ def measure(browser, base: str, turns: int) -> dict:
typing_s = time.perf_counter() - t0
m1 = metrics(cdp)
typed_ok = page.evaluate("() => window.__threadWeight.composerText()") == PRECHECK_KEYS + keys
+ lock_ms = lock_style_ms(cdp, page)
ctx.close()
n = len(keys)
selectors: dict[str, dict] = {}
@@ -270,6 +293,7 @@ def measure(browser, base: str, turns: int) -> dict:
"match_ms": sum(r["ms"] for r in selectors.values()),
"has_ms": sum(r["ms"] for s, r in selectors.items() if ":has(" in s),
"style_ms": 1000 * (m1["RecalcStyleDuration"] - m0["RecalcStyleDuration"]) / n,
+ "lock_ms": lock_ms,
"selectors": selectors,
}
@@ -485,7 +509,8 @@ def report(
f"{med(turns, 'has_ms'):.2f} ms/key, style recalc {med(turns, 'style_ms'):.1f} ms/key "
f"(tracing on; {runs[turns][-1]['precheck_style_ms']:.1f} ms/key untraced), "
f"{runs[turns][0]['shape']['nodes']:,} DOM nodes, {runs[turns][-1]['keys']} keys traced "
- f"in {runs[turns][-1]['typing_s']} s"
+ f"in {runs[turns][-1]['typing_s']} s, dialog/menu open or close "
+ f"{med(turns, 'lock_ms'):.1f} ms style recalc"
)
print("\n".join(lines))
if failures:
@@ -495,7 +520,9 @@ def report(
print(d)
print(f" {HEALTHY}")
return 1
- print("PASS: selector work per keystroke does not grow with the chat")
+ print(
+ "PASS: selector work per keystroke does not grow with the chat, and opening a dialog or menu does not restyle it"
+ )
return 0
@@ -540,6 +567,14 @@ def main() -> int:
details += top_selectors(large, only_has = True)
details += pin_down(browser, base)
details.append(" " + HINT)
+ if not failures and large.get("lock_ms", 0.0) > MAX_LOCK_MS:
+ failures.append(
+ f"opening or closing a dialog or menu costs {large['lock_ms']:.0f} ms of style recalc at "
+ f"{LARGE} turns, budget {MAX_LOCK_MS:.0f} ms ({large['lock_ms'] / MAX_LOCK_MS:.1f}x over). "
+ "Radix writes pointer-events: none on <body> and the thread inherits it, so every message "
+ "restyles. It is possible the explicit pointer-events on .aui-thread-viewport in index.css "
+ "(the modal-layer cover rules) was removed or overridden, but we cannot be sure"
+ )
if not failures:
small = measure(browser, base, SMALL)
runs[SMALL].append(small)