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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: key the modal pointer-lock rules off attributes that never sit above the thread (#17006)
Daniel Hanbe2e825ceedd
diff --git a/studio/frontend/smoke-thread-weight-main.tsx b/studio/frontend/smoke-thread-weight-main.tsxindex ba094e39b6c..7b7077e7f37 100644--- a/studio/frontend/smoke-thread-weight-main.tsx+++ b/studio/frontend/smoke-thread-weight-main.tsx@@ -27,6 +27,7 @@ import {import { type ReactElement, useEffect, useState } from "react";import { createRoot } from "react-dom/client";import "./src/index.css";+import { watchModalPointerLock } from "./src/lib/modal-pointer-lock";// Answer ForkCountBadge GETs in-page: a Playwright-side answer would add a CDP round trip per// assistant message inside the timed region.@@ -477,4 +478,7 @@ const root = document.getElementById("root");if (!root) {throw new Error("missing #root");}+// As in main.tsx: the gate's modal lock check then times the attributes the app mirrors from the+// body lock, not a bare inline style the modal rules no longer read.+watchModalPointerLock(document);createRoot(root).render(<RouterProvider router={router as unknown as never} />);diff --git a/studio/frontend/src/index.css b/studio/frontend/src/index.cssindex a451ce8b7c4..f405276e664 100644--- a/studio/frontend/src/index.css+++ b/studio/frontend/src/index.css@@ -2153,11 +2153,17 @@ html[data-chat-font] .aui-root {about 40k elements at 100 turns, 0.45 s in Chromium and 2.4 s in WebKit per toggle. Anexplicit value on the scroller stops the inheritance there, and while the lock is up atransparent cover keeps the thread unclickable and unhovered exactly as before. Portaled- layers (z-50) stay above the cover. */+ layers (z-50) stay above the cover.+ The rules below key on attributes that src/lib/modal-pointer-lock.ts mirrors from that body+ lock, never on the body's inline style: an attribute selector on an ancestor of the thread made+ WebKit walk every message on each toggle (about 45 ms per open and close at 150 turns).+ data-modal-lock-thread sits on the thread roots, data-modal-lock-path on their ancestors and+ data-modal-lock-region on every other subtree of the page. */:where(.aui-thread-viewport) {pointer-events: auto;}- body[style*="pointer-events: none"] .aui-thread-root::after {+ .aui-thread-root[data-modal-lock-thread]::after,+ [data-modal-lock-region] .aui-thread-root::after {content: "";position: absolute;inset: 0;@@ -2168,11 +2174,12 @@ html[data-chat-font] .aui-root {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 alistener 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;+ static class, so the lock toggle only looks at them (an :is() subject here made every toggle+ restyle the thread in Chromium: 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'scompositor 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 {+ [data-modal-lock-region] .chat-artifact-pop-surface .side-pane-lock-cover::after,+ [data-modal-lock-region].chat-artifact-pop-surface .side-pane-lock-cover::after {content: "";position: absolute;inset: 0;@@ -2181,11 +2188,12 @@ html[data-chat-font] .aui-root {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] *) {+ menu has made a lower layer (Radix writes pointer-events: none on it, mirrored as+ data-modal-lock-lower) 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"])[data-modal-lock-lower] .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,@@ -2193,8 +2201,10 @@ html[data-chat-font] .aui-root {Left live: the top dialog (contained or portaled), every popper popup, the thread (its coverblocks it, and its many restorations would restyle on each toggle) and window chrome, toasts andoverlays 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 *) {+ CSS (an open disclosure arrow) rather than with the class. Class-keyed like the rule above; the+ region and path attributes together cover every element under <body> outside the thread roots. */+ [data-modal-lock-region] :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 *),+ :is([data-modal-lock-region], [data-modal-lock-path]):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;}diff --git a/studio/frontend/src/lib/modal-pointer-lock.ts b/studio/frontend/src/lib/modal-pointer-lock.tsnew file mode 100644index 00000000000..38a8b3eea8b--- /dev/null+++ b/studio/frontend/src/lib/modal-pointer-lock.ts@@ -0,0 +1,164 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++/**+ * Radix writes `pointer-events: none` on <body> while a modal layer is open. Rules keyed on that inline+ * style (`body[style*=...] X`) made WebKit re-match every element under <body> on each flip, about 45 ms+ * per open and close on a 150-turn chat. This mirrors the lock onto attributes that never sit above the+ * thread, so a toggle only reaches the elements the rules style:+ * - `data-modal-lock-thread` on each thread root, `data-modal-lock-path` on its ancestors;+ * - `data-modal-lock-region` on every other child of those ancestors (the rest of the page);+ * - `data-modal-lock-lower` on a dialog, menu or listbox a stacked modal layer pushed below it.+ * Idempotent: one watcher per document.+ */++export const MODAL_LOCK_THREAD_ATTR = "data-modal-lock-thread";+export const MODAL_LOCK_PATH_ATTR = "data-modal-lock-path";+export const MODAL_LOCK_REGION_ATTR = "data-modal-lock-region";+export const MODAL_LOCK_LOWER_ATTR = "data-modal-lock-lower";++const THREAD_ROOT_CLASS = "aui-thread-root";+const LAYER_ROLES = new Set(["dialog", "alertdialog", "menu", "listbox"]);+const LAYER_SELECTOR = '[role="dialog"], [role="alertdialog"], [role="menu"], [role="listbox"]';++type Attr =+ | typeof MODAL_LOCK_THREAD_ATTR+ | typeof MODAL_LOCK_PATH_ATTR+ | typeof MODAL_LOCK_REGION_ATTR;++interface LockWatcher {+ locked: boolean;+ marks: Map<Element, Attr>;+ lower: Set<Element>;+ structure: MutationObserver;+ layers: MutationObserver;+}++const watchers = new WeakMap<Document, LockWatcher>();++function isBodyLocked(doc: Document): boolean {+ return doc.body?.style.pointerEvents === "none";+}++function isLowerLayer(element: Element): boolean {+ const role = element.getAttribute("role");+ return (+ role !== null &&+ LAYER_ROLES.has(role) &&+ (element as HTMLElement).style?.pointerEvents === "none"+ );+}++/** Thread roots, their ancestors under <body>, and every other child of those ancestors. */+function desiredMarks(doc: Document): { marks: Map<Element, Attr>; path: Element[] } {+ const body = doc.body;+ const marks = new Map<Element, Attr>();+ const onPath = new Set<Element>([body]);+ const roots = Array.from(body.getElementsByClassName(THREAD_ROOT_CLASS));+ for (const root of roots) {+ // A thread root nested in another one stays inside that one (it is never split).+ if (roots.some((other) => other !== root && other.contains(root))) continue;+ marks.set(root, MODAL_LOCK_THREAD_ATTR);+ for (let node = root.parentElement; node && node !== body; node = node.parentElement) {+ if (onPath.has(node)) break;+ onPath.add(node);+ }+ }+ for (const node of onPath) {+ if (node !== body) marks.set(node, MODAL_LOCK_PATH_ATTR);+ for (const child of node.children) {+ if (!onPath.has(child) && !marks.has(child)) marks.set(child, MODAL_LOCK_REGION_ATTR);+ }+ }+ return { marks, path: [...onPath] };+}++function applyMarks(watcher: LockWatcher, next: Map<Element, Attr>): void {+ for (const [element, attr] of watcher.marks) {+ if (next.get(element) !== attr) element.removeAttribute(attr);+ }+ for (const [element, attr] of next) {+ if (watcher.marks.get(element) !== attr) element.setAttribute(attr, "");+ }+ watcher.marks = next;+}++function markLower(watcher: LockWatcher, element: Element): void {+ if (isLowerLayer(element)) {+ if (!watcher.lower.has(element)) {+ element.setAttribute(MODAL_LOCK_LOWER_ATTR, "");+ watcher.lower.add(element);+ }+ } else if (watcher.lower.delete(element)) {+ element.removeAttribute(MODAL_LOCK_LOWER_ATTR);+ }+}++function syncStructure(doc: Document, watcher: LockWatcher): void {+ const { marks, path } = desiredMarks(doc);+ applyMarks(watcher, marks);+ watcher.structure.disconnect();+ for (const node of path) watcher.structure.observe(node, { childList: true });+}++function lock(doc: Document, watcher: LockWatcher): void {+ watcher.locked = true;+ syncStructure(doc, watcher);+ // A layer that was already open (a non-modal menu under the new dialog) turned lower in the same+ // commit. Layers are never inside a thread, so only the regions are searched.+ for (const [element, attr] of watcher.marks) {+ if (attr !== MODAL_LOCK_REGION_ATTR) continue;+ markLower(watcher, element);+ for (const layer of element.querySelectorAll(LAYER_SELECTOR)) markLower(watcher, layer);+ }+ watcher.layers.observe(doc.body, {+ attributes: true,+ attributeFilter: ["style"],+ subtree: true,+ });+}++function unlock(watcher: LockWatcher): void {+ watcher.locked = false;+ watcher.structure.disconnect();+ watcher.layers.disconnect();+ applyMarks(watcher, new Map());+ for (const element of watcher.lower) element.removeAttribute(MODAL_LOCK_LOWER_ATTR);+ watcher.lower.clear();+}++/** Mirror Radix's body pointer-events lock onto the attributes index.css keys its modal rules on. */+export function watchModalPointerLock(doc: Document = document): () => void {+ const existing = watchers.get(doc);+ if (existing || typeof MutationObserver === "undefined" || !doc.body) {+ return () => undefined;+ }+ const watcher: LockWatcher = {+ locked: false,+ marks: new Map(),+ lower: new Set(),+ structure: new MutationObserver(() => {+ if (watcher.locked) syncStructure(doc, watcher);+ }),+ layers: new MutationObserver((records) => {+ for (const record of records) {+ if (record.target !== doc.body) markLower(watcher, record.target as Element);+ }+ }),+ };+ watchers.set(doc, watcher);+ const read = () => {+ const next = isBodyLocked(doc);+ if (next === watcher.locked) return;+ if (next) lock(doc, watcher);+ else unlock(watcher);+ };+ const body = new MutationObserver(read);+ body.observe(doc.body, { attributes: true, attributeFilter: ["style"] });+ read();+ return () => {+ body.disconnect();+ unlock(watcher);+ watchers.delete(doc);+ };+}diff --git a/studio/frontend/src/main.tsx b/studio/frontend/src/main.tsxindex 6fc63864fed..d41bf82f407 100644--- a/studio/frontend/src/main.tsx+++ b/studio/frontend/src/main.tsx@@ -42,6 +42,7 @@ 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 { watchModalPointerLock } from "./lib/modal-pointer-lock";import { watchOverlayScrollbarGutter } from "./lib/overlay-scrollbar";import { pinPointerListenerRegions } from "./lib/pointer-listener-pin";import { watchSpellCheck } from "./lib/spellcheck";@@ -94,6 +95,7 @@ watchInputModality(window);// Before any panel group mounts: their document pointer listeners then never change WebKit's page-wide set.pinPointerListenerRegions(document);watchClosingDialogFocus(document);+watchModalPointerLock(document);watchSpellCheck(window);watchTimeFormat(window);diff --git a/studio/frontend/tests/modal-lock-thread-cover.test.ts b/studio/frontend/tests/modal-lock-thread-cover.test.tsindex 777005f49ff..f0ba5999bc0 100644--- a/studio/frontend/tests/modal-lock-thread-cover.test.ts+++ b/studio/frontend/tests/modal-lock-thread-cover.test.ts@@ -22,7 +22,11 @@ test("the thread scroller does not inherit a modal layer's body pointer-events l});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');+ // Keyed on attributes src/lib/modal-pointer-lock.ts mirrors from the body lock: on the thread+ // root itself, or on a page region holding a thread root it did not find.+ const cover = rule(+ '.aui-thread-root[data-modal-lock-thread]::after,\n\t[data-modal-lock-region] .aui-thread-root::after',+ );assert.match(cover, /content: "";/);assert.match(cover, /position: absolute;/);assert.match(cover, /inset: 0;/);@@ -36,5 +40,6 @@ test("while the lock is up a cover keeps the thread unclickable, below portaledreadSrc("components/assistant-ui/thread.tsx"),/className="aui-root aui-thread-root relative /,);- assert.equal(CSS.split(".aui-thread-root::after").length - 1, 1);+ assert.equal(CSS.split(".aui-thread-root[data-modal-lock-thread]::after").length - 1, 1);+ assert.equal(CSS.split(" .aui-thread-root::after").length - 1, 1);});diff --git a/studio/frontend/tests/modal-pointer-lock.test.ts b/studio/frontend/tests/modal-pointer-lock.test.tsnew file mode 100644index 00000000000..49e2a919946--- /dev/null+++ b/studio/frontend/tests/modal-pointer-lock.test.ts@@ -0,0 +1,249 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++// Radix writes pointer-events: none on <body> for each modal layer. Rules keyed on that inline+// style (body[style*=...] X) made WebKit walk every element under <body>, the whole thread+// included, on each open and close. These pin that the modal rules key on attributes that never+// sit above a thread root, and that the watcher marks the page so the rules keep their meaning.++import assert from "node:assert/strict";+import test from "node:test";++import { readSrc } from "./helpers/kit.ts";++type Init = { childList?: boolean; attributes?: boolean; subtree?: boolean; attributeFilter?: string[] };++class FakeElement {+ attrs = new Map<string, string>();+ children: FakeElement[] = [];+ parentElement: FakeElement | null = null;+ style = { pointerEvents: "" };+ name: string;+ constructor(name: string, className = "", role?: string) {+ this.name = name;+ if (className) this.attrs.set("class", className);+ if (role) this.attrs.set("role", role);+ }+ append(...kids: FakeElement[]): this {+ for (const kid of kids) {+ kid.parentElement = this;+ this.children.push(kid);+ }+ return this;+ }+ getAttribute(name: string): string | null {+ return this.attrs.get(name) ?? null;+ }+ setAttribute(name: string, value: string): void {+ this.attrs.set(name, value);+ }+ removeAttribute(name: string): void {+ this.attrs.delete(name);+ }+ hasAttribute(name: string): boolean {+ return this.attrs.has(name);+ }+ descendants(): FakeElement[] {+ return this.children.flatMap((kid) => [kid, ...kid.descendants()]);+ }+ contains(other: FakeElement): boolean {+ return other === this || this.descendants().includes(other);+ }+ getElementsByClassName(name: string): FakeElement[] {+ return this.descendants().filter((el) => (el.getAttribute("class") ?? "").split(" ").includes(name));+ }+ querySelectorAll(selector: string): FakeElement[] {+ assert.match(selector, /\[role="dialog"\]/);+ return this.descendants().filter((el) =>+ ["dialog", "alertdialog", "menu", "listbox"].includes(el.getAttribute("role") ?? ""),+ );+ }+}++const observers: { cb: (records: unknown[]) => void; targets: [FakeElement, Init][] }[] = [];+class FakeMutationObserver {+ entry: (typeof observers)[number];+ constructor(cb: (records: unknown[]) => void) {+ this.entry = { cb, targets: [] };+ observers.push(this.entry);+ }+ observe(target: FakeElement, init: Init) {+ this.entry.targets.push([target, init]);+ }+ disconnect() {+ this.entry.targets = [];+ }+}++function deliverStyle(target: FakeElement): void {+ for (const o of observers) {+ const hit = o.targets.some(+ ([t, init]) =>+ init.attributeFilter?.includes("style") && (t === target || (init.subtree && t.contains(target))),+ );+ if (hit) o.cb([{ type: "attributes", attributeName: "style", target }]);+ }+}++function deliverChildList(target: FakeElement): void {+ for (const o of observers) {+ if (o.targets.some(([t, init]) => t === target && init.childList)) {+ o.cb([{ type: "childList", target }]);+ }+ }+}++// body > [root > [sidebar > [row > action], shell > [header > toolbar, main > [threadRoot > viewport > msgs]]], portal]+const body = new FakeElement("body");+const root = new FakeElement("root");+const sidebar = new FakeElement("sidebar");+const rowAction = new FakeElement("rowAction", "sidebar-row-action");+const shell = new FakeElement("shell", "pointer-events-auto");+const header = new FakeElement("header");+const toolbar = new FakeElement("toolbar", "pointer-events-auto");+const main = new FakeElement("main");+const threadRoot = new FakeElement("threadRoot", "aui-root aui-thread-root relative");+const viewport = new FakeElement("viewport", "aui-thread-viewport");+const messages = Array.from({ length: 50 }, (_, i) => new FakeElement(`msg${i}`, "pointer-events-auto"));+const menuPortal = new FakeElement("menuPortal");+const nonModalMenu = new FakeElement("nonModalMenu", "", "menu");+body.append(+ root.append(+ sidebar.append(new FakeElement("row").append(rowAction)),+ shell.append(header.append(toolbar), main.append(threadRoot.append(viewport.append(...messages)))),+ ),+ menuPortal.append(nonModalMenu),+);++Object.assign(globalThis, { MutationObserver: FakeMutationObserver });+const doc = { body } as unknown as Document;+const lock = await import("../src/lib/modal-pointer-lock.ts");+const ATTRS = [+ lock.MODAL_LOCK_THREAD_ATTR,+ lock.MODAL_LOCK_PATH_ATTR,+ lock.MODAL_LOCK_REGION_ATTR,+ lock.MODAL_LOCK_LOWER_ATTR,+];++function marked(): Record<string, string[]> {+ const out: Record<string, string[]> = {};+ for (const el of body.descendants()) {+ for (const attr of ATTRS) if (el.hasAttribute(attr)) (out[attr] ??= []).push(el.name);+ }+ return out;+}++/** Inside one region, or a path element, or a thread root (whose subtree no rule reaches). */+function coveredOnce(el: FakeElement): boolean {+ let regions = 0;+ for (let node: FakeElement | null = el; node && node !== body; node = node.parentElement) {+ if (node.hasAttribute(lock.MODAL_LOCK_REGION_ATTR)) regions += 1;+ if (node.hasAttribute(lock.MODAL_LOCK_THREAD_ATTR)) return regions === 0;+ }+ return regions === 1 || (regions === 0 && el.hasAttribute(lock.MODAL_LOCK_PATH_ATTR));+}++const stop = lock.watchModalPointerLock(doc);++test("no modal rule keys on an inline style, and lock attributes above a thread are subject-only", () => {+ const css = readSrc("index.css");+ // Any [style*=...] selector makes every inline style flip on an ancestor walk its subtree in WebKit.+ assert.doesNotMatch(css, /\[style[*^$~|]?=/);+ for (const attr of ["data-modal-lock-thread", "data-modal-lock-path"]) {+ let uses = 0;+ for (let at = css.indexOf(`[${attr}]`); at >= 0; at = css.indexOf(`[${attr}]`, at + 1)) {+ uses += 1;+ // Rest of this compound: a combinator at paren depth 0 would make it an ancestor.+ let depth = 0;+ for (let i = at + attr.length + 2; i < css.length; i++) {+ const ch = css[i];+ if (ch === "(") depth += 1;+ else if (ch === ")") depth -= 1;+ if (depth < 0) depth = 0; // closed the :is() this attribute sits in+ if (depth > 0) continue;+ if (ch === "," || ch === "{") break;+ assert.ok(!/[\s>+~]/.test(ch) || /^\s*[,{]/.test(css.slice(i)), `${attr} used as an ancestor near ${css.slice(at, at + 80)}`);+ }+ }+ assert.ok(uses > 0, attr);+ }+ assert.match(readSrc("main.tsx"), /watchModalPointerLock\(document\);/);+});++test("nothing is marked until the body lock goes up", () => {+ assert.deepEqual(marked(), {});+});++test("the lock splits the page into regions around the thread and marks no message", () => {+ body.style.pointerEvents = "none";+ deliverStyle(body);+ assert.deepEqual(marked()[lock.MODAL_LOCK_THREAD_ATTR], ["threadRoot"]);+ assert.deepEqual(marked()[lock.MODAL_LOCK_PATH_ATTR]?.sort(), ["main", "root", "shell"]);+ assert.deepEqual(marked()[lock.MODAL_LOCK_REGION_ATTR]?.sort(), ["header", "menuPortal", "sidebar"]);+ for (const el of body.descendants()) {+ if (threadRoot.contains(el) && el !== threadRoot) {+ assert.equal(ATTRS.some((attr) => el.hasAttribute(attr)), false, `${el.name} inside the thread was marked`);+ } else {+ assert.ok(coveredOnce(el), `${el.name} is not covered by exactly one lock rule scope`);+ }+ }+});++test("a child mounted next to the thread while locked joins a region", () => {+ const banner = new FakeElement("banner", "pointer-events-auto");+ main.append(banner);+ deliverChildList(main);+ assert.ok(banner.hasAttribute(lock.MODAL_LOCK_REGION_ATTR));+ // A child inside a region needs nothing: the region's descendant rule reaches it.+ const late = new FakeElement("late", "pointer-events-auto");+ header.append(late);+ assert.ok(coveredOnce(late));+});++test("a stacked modal layer marks the layer under it as lower, and lifts it again", () => {+ const dialog = new FakeElement("dialog", "", "dialog");+ const dialogPortal = new FakeElement("dialogPortal").append(dialog);+ body.append(dialogPortal);+ deliverChildList(body);+ assert.ok(dialogPortal.hasAttribute(lock.MODAL_LOCK_REGION_ATTR));+ dialog.style.pointerEvents = "none";+ deliverStyle(dialog);+ assert.ok(dialog.hasAttribute(lock.MODAL_LOCK_LOWER_ATTR));+ dialog.style.pointerEvents = "auto";+ deliverStyle(dialog);+ assert.equal(dialog.hasAttribute(lock.MODAL_LOCK_LOWER_ATTR), false);+ // Inline pointer-events on something that is not a layer is not a lower layer.+ toolbar.style.pointerEvents = "none";+ deliverStyle(toolbar);+ assert.equal(toolbar.hasAttribute(lock.MODAL_LOCK_LOWER_ATTR), false);+ toolbar.style.pointerEvents = "";+});++test("unlocking clears every mark and stops watching the page", () => {+ body.style.pointerEvents = "";+ deliverStyle(body);+ assert.deepEqual(marked(), {});+ const active = observers.filter((o) => o.targets.length > 0);+ assert.equal(active.length, 1, "only the body style observer stays connected");+ assert.deepEqual(active[0].targets.map(([t]) => t.name), ["body"]);+});++test("a layer already lower when the lock goes up is marked at once", () => {+ nonModalMenu.style.pointerEvents = "none";+ body.style.pointerEvents = "none";+ deliverStyle(body);+ assert.ok(nonModalMenu.hasAttribute(lock.MODAL_LOCK_LOWER_ATTR));+ body.style.pointerEvents = "";+ deliverStyle(body);+ assert.deepEqual(marked(), {});+ nonModalMenu.style.pointerEvents = "";+});++test("a second watcher on the same document is a no-op", () => {+ const before = observers.length;+ const again = lock.watchModalPointerLock(doc);+ assert.equal(observers.length, before);+ again();+ stop();+ assert.equal(observers.filter((o) => o.targets.length > 0).length, 0);+});diff --git a/studio/frontend/tests/webkit-modal-page-restyle.test.ts b/studio/frontend/tests/webkit-modal-page-restyle.test.tsindex a2a4334cb61..8a2f9b70582 100644--- a/studio/frontend/tests/webkit-modal-page-restyle.test.ts+++ b/studio/frontend/tests/webkit-modal-page-restyle.test.ts@@ -106,7 +106,7 @@ test("a closing dialog gives up focus when its exit animation starts", () => {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';+ "[data-modal-lock-region] .chat-artifact-pop-surface .side-pane-lock-cover::after,\n\t[data-modal-lock-region].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;"]) {@@ -116,8 +116,8 @@ test("the side pane sits under the same modal cover as the thread", () => {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).+ // Keyed on a static class on the pane roots, which also position the cover: an :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"/);});@@ -125,15 +125,17 @@ test("the side pane sits under the same modal cover as the thread", () => {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] *)';+ ':is([role="dialog"], [role="alertdialog"], [role="menu"], [role="listbox"])[data-modal-lock-lower] .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 *)';+ // Page restorations (toolbars, the Downloads card) go inert under the body lock, with one rule:+ // inside a page region, or on a region root or a thread root's ancestor itself.+ const not =+ ':not(.aui-thread-root *):not([role="dialog"] *):not([role="alertdialog"] *):not([data-radix-popper-content-wrapper] *):not(.modal-pe-live):not(.modal-pe-live *)';+ const page = `[data-modal-lock-region] :is(.pointer-events-auto, .sidebar-row-action)${not},\n\t:is([data-modal-lock-region], [data-modal-lock-path]):is(.pointer-events-auto, .sidebar-row-action)${not}`;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.