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: browser pane opens without per-frame thread work on long chats (#17282)

Daniel Hanab9845e696ab
diff --git a/studio/frontend/src/features/chat/chat-page.tsx b/studio/frontend/src/features/chat/chat-page.tsx
index 93bc03c419e..bd018a37682 100644
--- a/studio/frontend/src/features/chat/chat-page.tsx
+++ b/studio/frontend/src/features/chat/chat-page.tsx
@@ -26,6 +26,7 @@ import {
useModelReasoningEffortStore,
} from "@/features/model-picker";
import { ProjectComposer, Thread } from "@/components/assistant-ui/thread";
+import { rowReachPx } from "@/components/assistant-ui/distant-rows";
import { LibraryAttachmentTargetContext } from "@/features/library";
import { usePlatformStore } from "@/config/env";
import { CopyableErrorChip } from "@/components/ui/copyable-error-chip";
@@ -649,6 +650,20 @@ function browserPanelDefaultSize(split: HTMLElement | null | undefined): string
return `${Math.min(50, Math.max(30, (BROWSER_PANEL_DEFAULT_PX / width) * 100))}%`;
}
const ARTIFACT_PANEL_TRANSITION_MS = 260;
+const ARTIFACT_LAYOUT_INSTANT_ATTRIBUTE = "data-artifact-layout-instant";
+
+/** A sliding width re-wraps every row in reach each frame, so a taller chat resizes in one step. */
+function markInstantLayout(surface: HTMLElement | null): void {
+ const split = surface?.closest<HTMLElement>(".chat-artifact-split");
+ if (!split) return;
+ const viewport = split.querySelector<HTMLElement>("#chat-thread .aui-thread-viewport");
+ split.toggleAttribute(
+ ARTIFACT_LAYOUT_INSTANT_ATTRIBUTE,
+ viewport !== null &&
+ viewport.clientHeight > 0 &&
+ viewport.scrollHeight > viewport.clientHeight + 2 * rowReachPx(window.innerHeight),
+ );
+}
const ARTIFACT_SURFACE_POP_DELAY_MS = 150;
const SingleContent = memo(function SingleContent({
@@ -786,6 +801,7 @@ const SingleContent = memo(function SingleContent({
setIsArtifactLayoutAnimating(true);
let resizeFrameId = 0;
const prepFrameId = window.requestAnimationFrame(() => {
+ markInstantLayout(contextSurfaceRef.current);
resizeFrameId = window.requestAnimationFrame(() => {
panel.resize(
showContextPanel
@@ -839,8 +855,12 @@ const SingleContent = memo(function SingleContent({
const root = surface?.closest<HTMLElement>("[data-chat-content-root]");
if (!surface || !root || !browserDocked) return;
let width = "";
+ // Children, not `:scope >`, which matches against the whole thread on every resize frame.
const insets = () =>
- root.querySelectorAll<HTMLElement>(":scope > [data-side-panel-inset]");
+ [...root.children].filter(
+ (element): element is HTMLElement =>
+ element instanceof HTMLElement && element.hasAttribute("data-side-panel-inset"),
+ );
const apply = () => {
for (const element of insets()) {
element.style.setProperty(
diff --git a/studio/frontend/src/index.css b/studio/frontend/src/index.css
index 842872abf2f..e1fbb15cfdb 100644
--- a/studio/frontend/src/index.css
+++ b/studio/frontend/src/index.css
@@ -3952,7 +3952,7 @@ html[data-chat-font] .aui-root {
white-space: nowrap;
}
- .chat-artifact-split[data-artifact-layout-animating="true"] > [data-panel] {
+ .chat-artifact-split[data-artifact-layout-animating="true"]:not([data-artifact-layout-instant]) > [data-panel] {
transition:
flex-basis 260ms var(--ease-out-cubic),
flex-grow 260ms var(--ease-out-cubic),
diff --git a/studio/frontend/src/lib/dismiss-click-streak.ts b/studio/frontend/src/lib/dismiss-click-streak.ts
index 60224954e4f..22f7d2e8421 100644
--- a/studio/frontend/src/lib/dismiss-click-streak.ts
+++ b/studio/frontend/src/lib/dismiss-click-streak.ts
@@ -3,8 +3,8 @@
// The OS counts a menu-dismissing press as click 1; later presses select as if it had not (caret, word, block).
-const OPEN_FLOATING =
- '[data-radix-popper-content-wrapper] :is([role="menu"],[role="listbox"],[role="dialog"])';
+const FLOATING_WRAPPER = "[data-radix-popper-content-wrapper]";
+const OPEN_FLOATING = `${FLOATING_WRAPPER} :is([role="menu"],[role="listbox"],[role="dialog"])`;
const TEXT_ENTRY =
'input,textarea,select,[contenteditable]:not([contenteditable="false"])';
@@ -151,10 +151,12 @@ export function installDismissClickStreakGuard(
const onPointerDown = (event: PointerEvent): void => {
// Capture phase: runs before Radix closes the menu.
const target = asElement(event.target);
+ // Wrapper first: the descendant selector walks a long chat on every press.
pressDismisses =
event.button === 0 &&
+ doc.querySelector(FLOATING_WRAPPER) !== null &&
doc.querySelector(OPEN_FLOATING) !== null &&
- !target?.closest("[data-radix-popper-content-wrapper]");
+ !target?.closest(FLOATING_WRAPPER);
};
const onMouseDown = (event: MouseEvent): void => {
diff --git a/studio/frontend/tests/browser-pane-open-cost.test.ts b/studio/frontend/tests/browser-pane-open-cost.test.ts
new file mode 100644
index 00000000000..9073830a378
--- /dev/null
+++ b/studio/frontend/tests/browser-pane-open-cost.test.ts
@@ -0,0 +1,25 @@
+// 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 PAGE = readSrc("features/chat/chat-page.tsx");
+const CSS = readSrc("index.css");
+
+test("the side-panel insets are found among the root's children, not by a :scope query over the thread", () => {
+ const effect = PAGE.slice(PAGE.indexOf("// Width on header/notice only"), PAGE.indexOf("const resizeObserver = new ResizeObserver"));
+ assert.match(effect, /const insets = \(\) =>\s*\[\.\.\.root\.children\]\.filter\(/);
+ assert.doesNotMatch(effect, /querySelectorAll[^;]*:scope > \[data-side-panel-inset\]/,
+ "the resize observer runs this each frame of the pane's open and close");
+});
+
+test("a long chat takes the pane's width in one step; a short one keeps the slide", () => {
+ assert.match(CSS, /\.chat-artifact-split\[data-artifact-layout-animating="true"\]:not\(\[data-artifact-layout-instant\]\) > \[data-panel\] \{\s*transition:/);
+ assert.match(PAGE, /import \{ rowReachPx \} from "@\/components\/assistant-ui\/distant-rows";/);
+ assert.match(PAGE, /split\.toggleAttribute\(\s*ARTIFACT_LAYOUT_INSTANT_ATTRIBUTE,\s*viewport !== null &&\s*viewport\.clientHeight > 0 &&\s*viewport\.scrollHeight > viewport\.clientHeight \+ 2 \* rowReachPx\(window\.innerHeight\),\s*\);/);
+ assert.match(PAGE, /const prepFrameId = window\.requestAnimationFrame\(\(\) => \{\s*markInstantLayout\(contextSurfaceRef\.current\);\s*resizeFrameId = window\.requestAnimationFrame\(\(\) => \{\s*panel\.resize\(/);
+ assert.doesNotMatch(PAGE.slice(PAGE.indexOf("function markInstantLayout"), PAGE.indexOf("const SingleContent")), /:scope >/);
+});
diff --git a/studio/frontend/tests/dismiss-click-streak.test.ts b/studio/frontend/tests/dismiss-click-streak.test.ts
index 8f48622f4da..2d6723740ac 100644
--- a/studio/frontend/tests/dismiss-click-streak.test.ts
+++ b/studio/frontend/tests/dismiss-click-streak.test.ts
@@ -167,3 +167,31 @@ test("the guard removes its listeners and is installed once for the app", () =>
assert.equal(f.count(), 0);
assert.match(readSrc("app/provider.tsx"), INSTALL_ONCE);
});
+
+test("a press with no floating wrapper skips the descendant menu query that walks a long chat", () => {
+ const queried: string[] = [];
+ let wrapper = false;
+ const listeners = new Map<string, Listener[]>();
+ const doc = {
+ addEventListener: (type: string, fn: Listener) =>
+ listeners.set(type, [...(listeners.get(type) ?? []), fn]),
+ removeEventListener: () => {},
+ querySelector: (selector: string) => {
+ queried.push(selector);
+ if (selector === "[data-radix-popper-content-wrapper]") return wrapper ? {} : null;
+ return wrapper ? {} : null;
+ },
+ } as unknown as Document;
+ installDismissClickStreakGuard(doc, () => null);
+ const press = () => {
+ for (const fn of listeners.get("pointerdown") ?? [])
+ fn({ target: { closest: () => null }, button: 0 } as unknown as Event);
+ };
+ press();
+ assert.deepEqual(queried, ["[data-radix-popper-content-wrapper]"]);
+ queried.length = 0;
+ wrapper = true;
+ press();
+ assert.equal(queried.length, 2, "with a wrapper present the open-menu check still runs");
+ assert.match(queried[1], /^\[data-radix-popper-content-wrapper\] :is\(\[role="menu"\]/);
+});