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.

Fix slow typing in long chats on Windows (#16656)

Lee Jacksonf49ae101a400
diff --git a/studio/frontend/smoke-chat-background-main.tsx b/studio/frontend/smoke-chat-background-main.tsx
index 6fe32529fb7..9d458f8c72a 100644
--- a/studio/frontend/smoke-chat-background-main.tsx
+++ b/studio/frontend/smoke-chat-background-main.tsx
@@ -11,6 +11,7 @@ import {
useChatBackground,
} from "./src/features/chat-background/storage";
import { TooltipProvider } from "./src/components/ui/tooltip";
+import { useMarkChatWelcome } from "./src/features/chat-background/welcome";
import "./src/index.css";
declare global {
interface Window {
@@ -24,6 +25,11 @@ window.__wallpaperSmoke = {
patch: patchBackground,
state: useBackgroundStore.getState,
};
+// Same root flag and nesting as ThreadWelcome, which the wallpaper CSS reads.
+function WelcomeFlag() {
+ useMarkChatWelcome();
+ return null;
+}
function App() {
const [conversation, setConversation] = useState(false),
[active, setActive] = useState(true),
@@ -81,6 +87,8 @@ function App() {
<div data-side-panel-inset="" className="chat-header-fade pointer-events-none absolute inset-x-0 top-[calc(var(--studio-content-top-inset,0px)+48px)] z-20 h-6 bg-gradient-to-b from-background to-transparent" />
<div className="aui-thread-root relative h-full">
<div className="aui-thread-viewport h-full p-8">
+ {!conversation && <WelcomeFlag />}
+ <div className={conversation ? undefined : "aui-thread-welcome-root"}>
<div
className={
conversation
@@ -114,6 +122,7 @@ function App() {
/>
</div>
</div>
+ </div>
</div>
</div>
</div>
diff --git a/studio/frontend/src/features/chat-background/index.ts b/studio/frontend/src/features/chat-background/index.ts
index 9c2b2b49f7c..019fb78dcd9 100644
--- a/studio/frontend/src/features/chat-background/index.ts
+++ b/studio/frontend/src/features/chat-background/index.ts
@@ -7,5 +7,9 @@ export {
} from "./material";
export { MATERIAL_LABELS } from "./material-labels";
export { MATERIALS, type WindowMaterial } from "./model";
-export { useChatWelcomeShown, useMarkChatWelcome } from "./welcome";
+export {
+ useChatWelcomeShown,
+ useMarkChatCompare,
+ useMarkChatWelcome,
+} from "./welcome";
export { resetChatBackground, useBackgroundStore } from "./storage";
diff --git a/studio/frontend/src/features/chat-background/welcome.ts b/studio/frontend/src/features/chat-background/welcome.ts
index 7fc516942fc..5ee60dfb7f9 100644
--- a/studio/frontend/src/features/chat-background/welcome.ts
+++ b/studio/frontend/src/features/chat-background/welcome.ts
@@ -1,6 +1,6 @@
// 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 { useEffect, useSyncExternalStore } from "react";
+import { useEffect, useLayoutEffect, useSyncExternalStore } from "react";
// Counted, not a flag: Compare mounts one welcome per pane.
let shown = 0;
@@ -15,7 +15,29 @@ function subscribe(listener: () => void) {
};
}
+/*
+ * Root flags for the wallpaper CSS. A descendant :has() on the workspace re-walks the whole
+ * thread on every keystroke, so the welcome and compare states are mirrored onto <html>
+ * in the same commit as the DOM they describe.
+ */
+export const ROOT_WELCOME = "data-chat-welcome";
+export const ROOT_COMPARE = "data-chat-compare";
+const rootCounts = new Map<string, number>();
+function useRootFlag(name: string): void {
+ useLayoutEffect(() => {
+ const root = document.documentElement;
+ rootCounts.set(name, (rootCounts.get(name) ?? 0) + 1);
+ root.setAttribute(name, "");
+ return () => {
+ const left = Math.max(0, (rootCounts.get(name) ?? 1) - 1);
+ rootCounts.set(name, left);
+ if (left === 0) root.removeAttribute(name);
+ };
+ }, [name]);
+}
+
export function useMarkChatWelcome(): void {
+ useRootFlag(ROOT_WELCOME);
useEffect(() => {
shown++;
emit();
@@ -26,6 +48,10 @@ export function useMarkChatWelcome(): void {
}, []);
}
+export function useMarkChatCompare(): void {
+ useRootFlag(ROOT_COMPARE);
+}
+
export function useChatWelcomeShown(): boolean {
return useSyncExternalStore(
subscribe,
diff --git a/studio/frontend/src/features/chat/chat-page.tsx b/studio/frontend/src/features/chat/chat-page.tsx
index cf940a82845..09a0523c92e 100644
--- a/studio/frontend/src/features/chat/chat-page.tsx
+++ b/studio/frontend/src/features/chat/chat-page.tsx
@@ -83,6 +83,7 @@ import {
useNativeModelDrop,
useNativePathLeasesSupported,
} from "@/features/native-intents";
+import { useMarkChatCompare } from "@/features/chat-background";
import { isNpuModelId } from "@/features/npu";
import { GuidedTour, useGuidedTourController } from "@/features/tour";
import { isTauri } from "@/lib/api-base";
@@ -1320,6 +1321,7 @@ function CompareShell({
children: ReactElement;
composer: ReactElement;
}): ReactElement {
+ useMarkChatCompare();
return (
<CompareHandlesProvider handlesRef={handlesRef}>
<div className="flex min-h-0 min-w-0 flex-1 basis-0 flex-col">
diff --git a/studio/frontend/src/index.css b/studio/frontend/src/index.css
index 2b457c437cb..6d3a64edc0e 100644
--- a/studio/frontend/src/index.css
+++ b/studio/frontend/src/index.css
@@ -6109,24 +6109,25 @@ html[data-find-bar-open] [data-sonner-toaster][data-y-position="top"] {
.chat-wallpaper[data-reduced] .chat-wallpaper-frame { animation: none; }
.chat-wallpaper[data-reduced] .chat-wallpaper-frame[data-departing] { display: none; }
/* Light New chat: sqrt(v) lifts the image but keeps the whole slider range live. */
-html:not(.dark)[data-glass] :is([data-wallpaper-workspace], [data-chat-content-root]):has(.aui-thread-welcome-center) .chat-wallpaper-frame:not([data-entering], [data-departing]) {
+html:not(.dark)[data-glass][data-chat-welcome] :is([data-wallpaper-workspace], [data-chat-content-root]) .chat-wallpaper-frame:not([data-entering], [data-departing]) {
opacity: min(1, calc(var(--wallpaper-visibility) * 2));
}
/* var() makes a bare sqrt() parse everywhere (opacity 1 where unsupported), hence @supports. */
@supports (opacity: sqrt(0.5)) {
- html:not(.dark)[data-glass] :is([data-wallpaper-workspace], [data-chat-content-root]):has(.aui-thread-welcome-center) .chat-wallpaper-frame:not([data-entering], [data-departing]) {
+ html:not(.dark)[data-glass][data-chat-welcome] :is([data-wallpaper-workspace], [data-chat-content-root]) .chat-wallpaper-frame:not([data-entering], [data-departing]) {
opacity: sqrt(var(--wallpaper-visibility));
}
}
-/* Conversations dim the crop; compare dims even an empty pane so both match. */
-:is([data-wallpaper-workspace], [data-chat-content-root]):has(> .chat-wallpaper[data-ready]):not([data-wallpaper-route="page"]):not(:has(.aui-thread-welcome-center)) > .chat-wallpaper,
-:is([data-wallpaper-workspace], [data-chat-content-root]):has(> .chat-wallpaper[data-ready]):not([data-wallpaper-route="page"]):has([data-tour="chat-compare-view"]) > .chat-wallpaper,
+/* Conversations dim the crop; compare dims even an empty pane so both match.
+ Welcome/compare come from root flags (welcome.ts): a descendant :has() here re-walks the thread per keystroke. */
+html:not([data-chat-welcome]) :is([data-wallpaper-workspace], [data-chat-content-root]):has(> .chat-wallpaper[data-ready]):not([data-wallpaper-route="page"]) > .chat-wallpaper,
+html[data-chat-compare] :is([data-wallpaper-workspace], [data-chat-content-root]):has(> .chat-wallpaper[data-ready]):not([data-wallpaper-route="page"]) > .chat-wallpaper,
.wallpaper-preview[data-wallpaper-conversation] > .chat-wallpaper { opacity: calc(.4 + .6 * var(--wallpaper-conversation, 0)); }
:is([data-wallpaper-workspace], [data-chat-content-root]):has(> .chat-wallpaper[data-ready]) :is(.aui-thread-viewport, [data-wallpaper-reading-surface]) {
background: color-mix(in srgb, var(--background) calc((1 - var(--wallpaper-safe, 0)) * (1 - .65 * var(--wallpaper-conversation, 0)) * 100%), transparent);
}
/* No second wash on the welcome view: it crushes mid-tones into a dark horizon. */
-:is([data-wallpaper-workspace], [data-chat-content-root]):has(> .chat-wallpaper[data-ready]) .aui-thread-viewport:has(.aui-thread-welcome-center) {
+:is([data-wallpaper-workspace], [data-chat-content-root]):has(> .chat-wallpaper[data-ready]) .aui-thread-viewport:has(> .aui-thread-welcome-root > .aui-thread-welcome-center) {
background: transparent;
}
:is([data-wallpaper-workspace], [data-chat-content-root]):has(> .chat-wallpaper[data-ready]) .unsloth-welcome-greeting {
@@ -6207,7 +6208,9 @@ html[data-chat-wallpaper-ready] [data-slot="window-titlebar"][data-viewport-back
.wallpaper-preview-composer { background: var(--background); }
}
-:is([data-wallpaper-workspace], [data-chat-content-root]):has(> .chat-wallpaper[data-ready] .chat-wallpaper-image[data-fade="false"]) .thread-bottom-fade {
+/* Keep both wallpaper paths child-only so typing in the chat does not invalidate the whole workspace. */
+:is([data-wallpaper-workspace], [data-chat-content-root]):has(> .chat-wallpaper[data-ready] > .chat-wallpaper-image[data-fade="false"]) .thread-bottom-fade,
+:is([data-wallpaper-workspace], [data-chat-content-root]):has(> .chat-wallpaper[data-ready] > .chat-wallpaper-frame > .chat-wallpaper-image[data-fade="false"]) .thread-bottom-fade {
display: none;
}
@@ -6329,7 +6332,7 @@ html[data-glass="macos"] .unsloth-composer-surface {
backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
--composer-shadow: inset 0 0 0 1px color-mix(in srgb, var(--foreground) 14%, transparent), inset 0 1px 0 rgb(255 255 255 / .08);
}
-html[data-glass] :is([data-wallpaper-workspace], [data-chat-content-root]):has(> .chat-wallpaper[data-ready]):not([data-wallpaper-route="page"]):not(:has(.aui-thread-welcome-center)) > .chat-wallpaper,
+html[data-glass]:not([data-chat-welcome]) :is([data-wallpaper-workspace], [data-chat-content-root]):has(> .chat-wallpaper[data-ready]):not([data-wallpaper-route="page"]) > .chat-wallpaper,
html[data-glass] [data-wallpaper-workspace][data-wallpaper-route="page"] > .chat-wallpaper[data-ready],
html[data-glass] .wallpaper-preview[data-wallpaper-conversation] > .chat-wallpaper {
opacity: calc(.7 * (.4 + .6 * var(--wallpaper-conversation, 0)));
@@ -6347,7 +6350,7 @@ html:not(.dark)[data-glass] [data-wallpaper-workspace][data-wallpaper-route="pag
html:not(.dark)[data-glass][data-chat-wallpaper-workspace-ready] [data-wallpaper-workspace][data-wallpaper-route="page"] > [data-slot="sidebar-inset"] {
--glass-page-wash: color-mix(in srgb, var(--glass-page-bg) min(96%, calc((max(var(--glass-tint), var(--glass-pane-floor)) - 12%) * var(--glass-opacity, 1))), transparent);
}
-html[data-glass] :is([data-wallpaper-workspace], [data-chat-content-root]):has(> .chat-wallpaper[data-ready]):not([data-wallpaper-route="page"]):not(:has(.aui-thread-welcome-center)) .unsloth-composer-surface,
+html[data-glass]:not([data-chat-welcome]) :is([data-wallpaper-workspace], [data-chat-content-root]):has(> .chat-wallpaper[data-ready]):not([data-wallpaper-route="page"]) .unsloth-composer-surface,
html[data-glass] .wallpaper-preview[data-wallpaper-conversation] .wallpaper-preview-composer {
--glass-composer-boost: 9%;
--glass-blur: calc(var(--glass-blur-base) * var(--glass-strength, 1) + 5px + var(--glass-repaint, 0) * .01px);
@@ -6961,7 +6964,9 @@ html[data-glass] [data-windows-wallpaper-page]:has(> .chat-wallpaper[data-ready]
pointer-events: none;
backdrop-filter: blur(max(22px, var(--glass-blur)));
}
-[data-windows-wallpaper-page]:has([data-windows-glass-frame]) > [data-slot="page-wallpaper-blur"] {
+/* Child path to the pinned sidebar's container (Sidebar spreads props there): this page also
+ holds the hidden chat, and a descendant :has() would walk it on every mutation. */
+[data-windows-wallpaper-page]:has(> [data-windows-glass-frame], > [data-slot="sidebar"] > [data-windows-glass-frame]) > [data-slot="page-wallpaper-blur"] {
border-top-left-radius: 4px;
}
/* A full-height page may extend under the Windows caption. Start its reading
diff --git a/studio/frontend/tests/thread-ancestor-has-scope.test.ts b/studio/frontend/tests/thread-ancestor-has-scope.test.ts
index d43933bfdb7..ed9c29d1729 100644
--- a/studio/frontend/tests/thread-ancestor-has-scope.test.ts
+++ b/studio/frontend/tests/thread-ancestor-has-scope.test.ts
@@ -11,6 +11,8 @@ import assert from "node:assert/strict";
import test from "node:test";
import ts from "@typescript/typescript6";
+import postcss from "postcss";
+import selectorParser from "postcss-selector-parser";
import { openingTag } from "./helpers/tsx-ast.ts";
@@ -98,3 +100,108 @@ test("index.css has no descendant-argument :has() on the panels that hold the th
css.match(/(?:#chat-thread|\.chat-artifact-split|\.chat-thread-pane)[^{},]*:has\((?!\s*>)/g) ?? [];
assert.deepEqual(offenders, [], `descendant-argument :has() on a thread ancestor: ${offenders.join(" | ")}`);
});
+
+// Elements that hold the whole thread: a descendant :has() on any of them re-walks every message.
+const THREAD_ANCESTORS = [
+ ["attribute", "data-wallpaper-workspace"],
+ ["attribute", "data-chat-content-root"],
+ // Same element as the workspace on Windows non-chat pages, where the chat stays mounted.
+ ["attribute", "data-windows-wallpaper-page"],
+ ["class", "aui-thread-viewport"],
+] as const;
+
+type Node = selectorParser.Node;
+
+// The compound (run of simple selectors between combinators) that `node` sits in.
+const compoundOf = (node: Node): Node[] => {
+ const parts = node.parent?.nodes ?? [];
+ const at = parts.indexOf(node as never);
+ let from = at;
+ while (from > 0 && parts[from - 1].type !== "combinator") from--;
+ let to = at;
+ while (to < parts.length - 1 && parts[to + 1].type !== "combinator") to++;
+ return parts.slice(from, to + 1) as Node[];
+};
+
+// :has() nested in :not()/:is()/:where() still anchors on the outer compound.
+const anchorCompound = (pseudo: selectorParser.Pseudo): Node[] => {
+ let node: Node = pseudo;
+ for (;;) {
+ const outer: Node | undefined = node.parent?.parent as Node | undefined;
+ if (!outer || !selectorParser.isPseudo(outer) || outer.value === ":has") break;
+ node = outer;
+ }
+ return compoundOf(node);
+};
+
+const isThreadAncestor = (compound: Node[]): boolean => {
+ const hits = (node: Node): boolean =>
+ THREAD_ANCESTORS.some(([type, value]) =>
+ node.type === type
+ && (type === "attribute" ? (node as selectorParser.Attribute).attribute : node.value) === value)
+ || (node.type === "pseudo" && node.value === ":is" && node.nodes.some((sel) => sel.nodes.some(hits)));
+ return compound.some(hits);
+};
+
+const childOnly = (path: selectorParser.Selector): boolean => {
+ if (path.first?.type !== "combinator" || path.first.value !== ">") return false;
+ let ok = true;
+ path.each((node) => {
+ if (node.type === "combinator" && node.value !== ">") ok = false;
+ });
+ return ok;
+};
+
+const descendantHasOnThreadAncestors = (cssText: string): string[] => {
+ const offenders: string[] = [];
+ postcss.parse(cssText).walkRules((rule) => {
+ if (!rule.selector.includes(":has(")) return;
+ selectorParser().astSync(rule.selector).walkPseudos((pseudo) => {
+ if (pseudo.value !== ":has" || !isThreadAncestor(anchorCompound(pseudo))) return;
+ for (const path of pseudo.nodes) {
+ if (!childOnly(path)) offenders.push(`${String(pseudo)} in ${rule.selector}`);
+ }
+ });
+ });
+ return offenders;
+};
+
+test("no descendant-argument :has() anchored on an element that holds the thread", () => {
+ const offenders = descendantHasOnThreadAncestors(readText("../src/index.css"));
+ assert.deepEqual(offenders, [], offenders.join("\n"));
+});
+
+test("the thread-ancestor :has() guard catches the shapes that regressed typing", () => {
+ const workspace = ":is([data-wallpaper-workspace], [data-chat-content-root])";
+ const bad = [
+ `${workspace}:has(> .chat-wallpaper[data-ready] .chat-wallpaper-image[data-fade="false"]) .thread-bottom-fade {}`,
+ `${workspace}:has(> .chat-wallpaper[data-ready]):not(:has(.aui-thread-welcome-center)) > .chat-wallpaper {}`,
+ `${workspace}:has([data-tour="chat-compare-view"]) > .chat-wallpaper {}`,
+ `${workspace} .aui-thread-viewport:has(.aui-thread-welcome-center) {}`,
+ `html:not(.dark)[data-glass] ${workspace}:has(.aui-thread-welcome-center) .chat-wallpaper-frame {}`,
+ "[data-windows-wallpaper-page]:has([data-windows-glass-frame]) > [data-slot=\"page-wallpaper-blur\"] {}",
+ ];
+ for (const css of bad) assert.equal(descendantHasOnThreadAncestors(css).length, 1, css);
+ const good = [
+ `${workspace}:has(> .chat-wallpaper[data-ready] > .chat-wallpaper-frame > .chat-wallpaper-image[data-fade="false"]) .thread-bottom-fade {}`,
+ `html:not([data-chat-welcome]) ${workspace}:has(> .chat-wallpaper[data-ready]) > .chat-wallpaper {}`,
+ `${workspace} .aui-thread-viewport:has(> .aui-thread-welcome-root > .aui-thread-welcome-center) {}`,
+ ".composer-pill-btn:has(.composer-pill-caret) {}",
+ ];
+ for (const css of good) assert.deepEqual(descendantHasOnThreadAncestors(css), [], css);
+});
+
+test("the welcome and compare views stamp the root flags the wallpaper CSS reads", () => {
+ const welcome = readText("../src/features/chat-background/welcome.ts");
+ assert.match(welcome, /ROOT_WELCOME = "data-chat-welcome"/);
+ assert.match(welcome, /ROOT_COMPARE = "data-chat-compare"/);
+ const thread = readText("../src/components/assistant-ui/thread.tsx");
+ const welcomeBody = thread.slice(thread.indexOf("const ThreadWelcome"));
+ assert.ok(welcomeBody.includes("useMarkChatWelcome();"), "ThreadWelcome must mark the welcome flag");
+ // The child-only viewport rule depends on this exact nesting.
+ assert.match(welcomeBody, /className="aui-thread-welcome-root[^"]*"[\s\S]{0,200}"aui-thread-welcome-center/);
+ const page = readText("../src/features/chat/chat-page.tsx");
+ const shell = page.slice(page.indexOf("function CompareShell"), page.indexOf("function CompareShell") + 800);
+ assert.ok(shell.includes("useMarkChatCompare();"), "CompareShell must mark the compare flag");
+ assert.ok(shell.includes('data-tour="chat-compare-view"'));
+});
diff --git a/studio/frontend/tests/window-material.test.ts b/studio/frontend/tests/window-material.test.ts
index 96efac6588d..1863f6f3276 100644
--- a/studio/frontend/tests/window-material.test.ts
+++ b/studio/frontend/tests/window-material.test.ts
@@ -165,7 +165,8 @@ test("the glass preference survives an account switch, and sign-in waits for the
test("glass over an open conversation dims the image and thickens only that composer", () => {
const css = readFileSync(new URL("../src/index.css", import.meta.url), "utf8");
- const conversation = String.raw`html\[data-glass\] :is\(\[data-wallpaper-workspace\], \[data-chat-content-root\]\):has\(> \.chat-wallpaper\[data-ready\]\):not\(\[data-wallpaper-route="page"\]\):not\(:has\(\.aui-thread-welcome-center\)\)`;
+ // Welcome comes from a root flag (welcome.ts), not a :has() walk over the whole thread.
+ const conversation = String.raw`html\[data-glass\]:not\(\[data-chat-welcome\]\) :is\(\[data-wallpaper-workspace\], \[data-chat-content-root\]\):has\(> \.chat-wallpaper\[data-ready\]\):not\(\[data-wallpaper-route="page"\]\)`;
assert.match(css, new RegExp(`${conversation} > \\.chat-wallpaper,[^{]*\\{\\n opacity: calc\\(\\.7 \\* `));
assert.match(css, new RegExp(`${conversation} \\.unsloth-composer-surface,[^{]*\\{\\n --glass-composer-boost: 9%;`));
assert.match(css, /calc\(\(max\(calc\(var\(--glass-tint\) \+ 14%\), var\(--glass-read-floor, 0%\), var\(--glass-composer-floor\)\) \+ var\(--glass-composer-boost, 0%\)\)/);
diff --git a/tests/studio/playwright_chat_background.js b/tests/studio/playwright_chat_background.js
index bd0e52864a2..e5eefb73ee6 100644
--- a/tests/studio/playwright_chat_background.js
+++ b/tests/studio/playwright_chat_background.js
@@ -103,6 +103,7 @@ async (page) => {
check(await page.getByRole('slider',{name:'Zoom',exact:true}).getAttribute('aria-valuenow')==='100','upload starts at default zoom');
await page.getByRole('combobox',{name:'Effect',exact:true}).click();await page.getByRole('option',{name:'Halftone',exact:true}).click();await settled('Halftone');
await page.getByRole('button',{name:'Toggle theme',exact:true}).click();await settled('Halftone');
+ check(await page.evaluate(()=>document.documentElement.hasAttribute('data-chat-welcome')&&getComputedStyle(document.querySelector('[data-chat-content-root] > .chat-wallpaper')).opacity==='1'),'welcome view is not dimmed');
await page.getByRole('button',{name:'Toggle conversation',exact:true}).click();
await page.waitForFunction(()=>getComputedStyle(document.querySelector('[data-chat-content-root] > .chat-wallpaper')).opacity==='0.4');
await page.emulateMedia({reducedMotion:'reduce'});