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 the autoscroll follow flag restyling the whole thread in WebKit (#17035)

Daniel Han78429b312265
diff --git a/studio/frontend/src/components/assistant-ui/thread.tsx b/studio/frontend/src/components/assistant-ui/thread.tsx
index 318646277ed..cb94fdcc330 100644
--- a/studio/frontend/src/components/assistant-ui/thread.tsx
+++ b/studio/frontend/src/components/assistant-ui/thread.tsx
@@ -2098,7 +2098,6 @@ export const Thread: FC<{
// bottom while the user scrolls up (see the hook for the full explanation).
const {
ref: viewportRef,
- markerRef,
context: autoScrollContext,
} = useIntentAwareAutoScroll();
@@ -2322,7 +2321,6 @@ export const Thread: FC<{
scrollToBottomOnRunStart={false}
scrollToBottomOnInitialize={false}
scrollToBottomOnThreadSwitch={false}
- ref={markerRef}
className="aui-thread-host hidden"
onDragEnter={onDragEnter}
onDragOver={onDragOver}
diff --git a/studio/frontend/src/components/assistant-ui/use-intent-aware-autoscroll.tsx b/studio/frontend/src/components/assistant-ui/use-intent-aware-autoscroll.tsx
index b3cbf2a2f2e..4530442b126 100644
--- a/studio/frontend/src/components/assistant-ui/use-intent-aware-autoscroll.tsx
+++ b/studio/frontend/src/components/assistant-ui/use-intent-aware-autoscroll.tsx
@@ -110,15 +110,10 @@ export function useIsThreadAtBottom(): boolean {
export function useIntentAwareAutoScroll(): {
ref: RefCallback<HTMLElement>;
- markerRef: RefCallback<HTMLElement>;
context: AutoScrollContextValue;
} {
const aui = useAui();
const cleanupRef = useRef<(() => void) | null>(null);
- const markerElRef = useRef<HTMLElement | null>(null);
- const markerRef = useCallback<RefCallback<HTMLElement>>((node) => {
- markerElRef.current = node;
- }, []);
const userDetachedRef = useRef(false);
const followUntilRef = useRef(0);
@@ -204,7 +199,11 @@ export function useIntentAwareAutoScroll(): {
const atBottomStrict = (): boolean =>
distanceFromBottom() <= AT_BOTTOM_THRESHOLD_PX;
- const marker = (): HTMLElement => markerElRef.current ?? el;
+ // On the viewport itself, matched as the subject: reaching it through the hidden host made
+ // WebKit restyle the whole thread on every flip (40-70 ms each at 150 turns).
+ const setFollowing = (on: boolean): void => {
+ el.toggleAttribute("data-aui-following", on);
+ };
// Room to scroll upward. Guards wheel/touch detach: a gesture on a viewport with nothing
// above can't express intent to leave the bottom and must not flip userDetachedRef, else
@@ -368,7 +367,7 @@ export function useIntentAwareAutoScroll(): {
(settling || performance.now() < followUntilRef.current);
if (following) {
- marker().toggleAttribute("data-aui-following", true);
+ setFollowing(true);
const scrollHeight = stabilize();
const pinned = atBottomStrict();
if (!pinned && scrollHeight > el.clientHeight) {
@@ -384,7 +383,7 @@ export function useIntentAwareAutoScroll(): {
return;
}
- marker().toggleAttribute("data-aui-following", false);
+ setFollowing(false);
setIsAtBottom(atBottomStrict());
};
@@ -691,7 +690,7 @@ export function useIntentAwareAutoScroll(): {
rafId = null;
}
clearSettleCheck();
- marker().removeAttribute("data-aui-following");
+ setFollowing(false);
resizeObserver.disconnect();
mutationObserver.disconnect();
el.removeEventListener("wheel", onWheel);
@@ -777,5 +776,5 @@ export function useIntentAwareAutoScroll(): {
],
);
- return { ref, markerRef, context };
+ return { ref, context };
}
diff --git a/studio/frontend/src/index.css b/studio/frontend/src/index.css
index 6ad6bce0d84..fb7c1f0b891 100644
--- a/studio/frontend/src/index.css
+++ b/studio/frontend/src/index.css
@@ -5410,7 +5410,9 @@ html.force-reduced-motion .sidebar-section-drop-line {
padding-left: calc(var(--spacing) * 5 + var(--thread-gutter-shift));
}
-.aui-thread-host[data-aui-following] + .aui-thread-root .aui-thread-viewport {
+/* Subject match only (use-intent-aware-autoscroll.tsx): reaching the viewport through a sibling of an
+ ancestor makes WebKit restyle the whole thread whenever the flag flips. */
+.aui-thread-viewport[data-aui-following] {
overflow-anchor: none;
}
diff --git a/studio/frontend/tests/thread-follow-flag-selector.test.ts b/studio/frontend/tests/thread-follow-flag-selector.test.ts
new file mode 100644
index 00000000000..463abbe2b3e
--- /dev/null
+++ b/studio/frontend/tests/thread-follow-flag-selector.test.ts
@@ -0,0 +1,65 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+// The autoscroll owner flips `data-aui-following` at the start and end of every follow window (any
+// width change: run settings, browser pane, sidebar). WebKit restyles every descendant of the
+// flipped element's later siblings when a rule reaches its subject through `+`/`~` and a descendant
+// combinator, which on a 150-turn thread cost 40-70 ms per flip. The flag therefore sits on the
+// viewport and is matched only as the subject.
+
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import { readSrc } from "./helpers/kit.ts";
+
+const HOOK = readSrc("components/assistant-ui/use-intent-aware-autoscroll.tsx");
+const THREAD = readSrc("components/assistant-ui/thread.tsx");
+const CSS = readSrc("index.css");
+
+function followSelectors(): string[] {
+ const out: string[] = [];
+ const re = /([^{}]*\[data-aui-following\][^{}]*)\{/g;
+ for (const m of CSS.matchAll(re)) {
+ const prelude = m[1].replace(/\/\*[\s\S]*?\*\//g, "").trim();
+ for (const sel of prelude.split(",")) out.push(sel.trim());
+ }
+ return out;
+}
+
+test("the follow flag is matched on the viewport itself", () => {
+ const selectors = followSelectors();
+ assert.ok(selectors.length > 0, "no data-aui-following rule left; the overflow-anchor guard is gone");
+ for (const sel of selectors) {
+ const at = sel.indexOf("[data-aui-following]");
+ const subject = sel.slice(at + "[data-aui-following]".length);
+ assert.doesNotMatch(subject, /[\s+~>]/, `${sel}: the flag must be on the subject compound, not an ancestor or sibling`);
+ assert.match(sel, /\.aui-thread-viewport\[data-aui-following\]$/, `${sel}: the flag belongs to the viewport`);
+ }
+});
+
+test("the hook flips the flag on the viewport, never on the portal host", () => {
+ assert.match(HOOK, /el\.toggleAttribute\("data-aui-following", on\)/);
+ assert.doesNotMatch(HOOK, /markerElRef|markerRef/);
+ assert.doesNotMatch(THREAD, /markerRef/);
+ // Every write goes through the one setter, teardown included.
+ const writes = [...HOOK.matchAll(/data-aui-following/g)].length;
+ assert.equal(writes, 1, "only the setter may name the flag");
+ assert.match(HOOK, /setFollowing\(true\);/);
+ assert.ok(
+ [...HOOK.matchAll(/setFollowing\(false\);/g)].length >= 2,
+ "the idle frame and teardown both clear the flag",
+ );
+});
+
+test("no thread rule reaches the viewport through a flagged sibling", () => {
+ // `.x[attr] + .aui-thread-root ...` invalidates the whole thread in WebKit on every flip.
+ const rules = CSS.replace(/\/\*[\s\S]*?\*\//g, "").match(/[^{}]+\{/g) ?? [];
+ for (const rule of rules) {
+ if (!/aui-thread-(root|viewport)/.test(rule)) continue;
+ assert.doesNotMatch(
+ rule,
+ /\[[^\]]+\]\s*[+~]/,
+ `${rule.trim()}: an attribute on a sibling restyles every row when it changes`,
+ );
+ }
+});