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: hold message hover still while a wheel scroll moves the thread (#13077)

Daniel Han064a873b2d8d
diff --git a/studio/frontend/src/components/assistant-ui/thread-wheel-hover.ts b/studio/frontend/src/components/assistant-ui/thread-wheel-hover.ts
new file mode 100644
index 00000000000..d4155e12587
--- /dev/null
+++ b/studio/frontend/src/components/assistant-ui/thread-wheel-hover.ts
@@ -0,0 +1,59 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+/** suppresses wheel-scroll hover churn while preserving Chromium hit-testing and drags (#12025). */
+
+// Chromium smooth-scroll animation can outlast the final wheel event by about 200ms.
+const WHEEL_TAIL_MS = 300;
+const SETTLE_MS = 150;
+const MESSAGE = "[data-message-id]";
+
+export function attachWheelHoverSuppression(viewport: HTMLElement): () => void {
+ let wheelAt = Number.NEGATIVE_INFINITY;
+ let timer: ReturnType<typeof setTimeout> | undefined;
+ let hovered: Element | null = null;
+ const settle = () => {
+ timer = undefined;
+ const now = viewport.querySelector(`${MESSAGE}:hover`);
+ if (now === hovered) return;
+ hovered?.dispatchEvent(new MouseEvent("mouseleave"));
+ now?.dispatchEvent(new MouseEvent("mouseenter"));
+ };
+ const onBoundary = (event: MouseEvent) => {
+ const target = event.target as Element | null;
+ if (!target?.matches?.(MESSAGE)) return;
+ if (timer !== undefined && event.buttons === 0) {
+ event.stopPropagation();
+ } else if (event.type === "mouseenter") {
+ hovered = target;
+ } else if (target === hovered) {
+ hovered = null;
+ }
+ };
+ const onWheel = (event: WheelEvent) => {
+ wheelAt = event.buttons ? Number.NEGATIVE_INFINITY : event.timeStamp;
+ // mounting under a still pointer sets `:hover` without mouseenter; wheel fires before scroll.
+ if (timer === undefined) {
+ hovered = viewport.querySelector(`${MESSAGE}:hover`);
+ }
+ };
+ const onScroll = (event: Event) => {
+ if (event.timeStamp - wheelAt > WHEEL_TAIL_MS) return;
+ clearTimeout(timer);
+ timer = setTimeout(settle, SETTLE_MS);
+ };
+ viewport.addEventListener("mouseenter", onBoundary, true);
+ viewport.addEventListener("mouseleave", onBoundary, true);
+ viewport.addEventListener("wheel", onWheel, { passive: true });
+ viewport.addEventListener("scroll", onScroll, { passive: true });
+ return () => {
+ viewport.removeEventListener("mouseenter", onBoundary, true);
+ viewport.removeEventListener("mouseleave", onBoundary, true);
+ viewport.removeEventListener("wheel", onWheel);
+ viewport.removeEventListener("scroll", onScroll);
+ if (timer !== undefined) {
+ clearTimeout(timer);
+ settle();
+ }
+ };
+}
diff --git a/studio/frontend/src/components/assistant-ui/thread.tsx b/studio/frontend/src/components/assistant-ui/thread.tsx
index 15046b93f43..8ca7ec308e2 100644
--- a/studio/frontend/src/components/assistant-ui/thread.tsx
+++ b/studio/frontend/src/components/assistant-ui/thread.tsx
@@ -39,6 +39,7 @@ import { UserMessageActionBar, UserMessageFooter } from "@/components/assistant-
import { useActionBarFocusReveal } from "@/components/assistant-ui/use-action-bar-focus-reveal";
import { MessageTiming } from "@/components/assistant-ui/message-timing";
import { attachThreadFastCopy } from "@/components/assistant-ui/thread-fast-copy";
+import { attachWheelHoverSuppression } from "@/components/assistant-ui/thread-wheel-hover";
import { threadHasResearchMessage } from "@/components/assistant-ui/thread-research-presence";
import { Reasoning, ReasoningGroup } from "@/components/assistant-ui/reasoning";
import { RagSourcesGroup } from "@/components/assistant-ui/rag-sources";
@@ -1967,24 +1968,21 @@ export const Thread: FC<{
[viewportRef],
);
- // Copying a selection out of the thread writes the plain text itself rather than letting the
- // browser serialise the selection, which spends over 99% of a long thread's copy building the
- // styled clipboard flavour. thread-fast-copy.ts holds the rule for when that substitution is
- // provably invisible, and hands the event back to the browser whenever it is not.
+ // plain-text copy skips styled data that consumes over 99% of long-thread copy time.
+ // thread-fast-copy.ts falls back to browser copying unless the substitution is invisible.
useEffect(() => {
if (!viewportEl) return;
return attachThreadFastCopy(viewportEl);
}, [viewportEl]);
- // Bottom spacer sizing. Invariant: chat never moves on its own on composer
- // resize.
- // - Grow (attachment added, multiline): grow at once; growth below the
- // scroll position is invisible and only adds room.
- // - Shrink (attachment removed): shrinking scrollHeight near the bottom
- // clamps scrollTop and yanks the chat down. Defer until invisible (user
- // scrolled up) or a bottom-pinning moment.
- // Applied imperatively so a remounted spacer can be sized from refs even
- // when composerHeight did not change (e.g. thread switch).
+ useEffect(() => {
+ if (!viewportEl) return;
+ return attachWheelHoverSuppression(viewportEl);
+ }, [viewportEl]);
+
+ // composer growth applies immediately because content below the scroll position is invisible.
+ // composer shrink waits until clamping scrollTop is safe or a bottom pin owns the motion.
+ // imperative sizing restores remounted spacers even when composerHeight is unchanged.
const spacerElRef = useRef<HTMLDivElement | null>(null);
const desiredSpacerPxRef = useRef<number | null>(null);
const appliedSpacerPxRef = useRef<number | null>(null);
diff --git a/studio/frontend/tests/thread-wheel-hover.test.ts b/studio/frontend/tests/thread-wheel-hover.test.ts
new file mode 100644
index 00000000000..dbc36f6d89d
--- /dev/null
+++ b/studio/frontend/tests/thread-wheel-hover.test.ts
@@ -0,0 +1,232 @@
+// 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 { mock, test } from "node:test";
+
+import { attachWheelHoverSuppression } from "../src/components/assistant-ui/thread-wheel-hover.ts";
+import { readSrc } from "./helpers/kit.ts";
+
+globalThis.MouseEvent ??=
+ class extends Event {} as unknown as typeof MouseEvent;
+
+function message(id: string) {
+ const got: string[] = [];
+ const el = {
+ id,
+ got,
+ hover: false,
+ matches: (selector: string) =>
+ selector === "[data-message-id]" ||
+ (selector === "[data-message-id]:hover" && el.hover),
+ dispatchEvent(event: Event) {
+ thread.boundary(event, el);
+ return true;
+ },
+ };
+ return el;
+}
+
+type Message = ReturnType<typeof message>;
+
+const thread = {
+ listeners: new Map<string, (event: Event) => void>(),
+ messages: [] as Message[],
+ boundary(event: Event, target: Message) {
+ let stopped = false;
+ Object.defineProperty(event, "target", { value: target });
+ event.stopPropagation = () => {
+ stopped = true;
+ };
+ this.listeners.get(`${event.type}:capture`)?.(event);
+ if (!stopped) target.got.push(event.type);
+ },
+ fire(type: string, extra: Record<string, unknown> = {}) {
+ this.listeners.get(type)?.({
+ type,
+ timeStamp: performance.now(),
+ ...extra,
+ } as unknown as Event);
+ },
+};
+
+function attach(...ids: string[]) {
+ thread.listeners.clear();
+ thread.messages = ids.map(message);
+ const viewport = {
+ addEventListener(
+ type: string,
+ fn: (event: Event) => void,
+ options?: boolean | AddEventListenerOptions,
+ ) {
+ thread.listeners.set(options === true ? `${type}:capture` : type, fn);
+ },
+ removeEventListener(type: string, _fn: unknown, options?: boolean) {
+ thread.listeners.delete(options === true ? `${type}:capture` : type);
+ },
+ querySelector: (selector: string) =>
+ thread.messages.find((m) => m.matches(selector)) ?? null,
+ };
+ return {
+ detach: attachWheelHoverSuppression(viewport as unknown as HTMLElement),
+ messages: thread.messages,
+ };
+}
+
+// the browser updates `:hover` even when the event does not reach assistant-ui.
+const enter = (m: Message, buttons = 0) => {
+ m.hover = true;
+ const event = new MouseEvent("mouseenter");
+ Object.defineProperty(event, "buttons", { value: buttons });
+ thread.boundary(event, m);
+};
+const leave = (m: Message, buttons = 0) => {
+ m.hover = false;
+ const event = new MouseEvent("mouseleave");
+ Object.defineProperty(event, "buttons", { value: buttons });
+ thread.boundary(event, m);
+};
+
+test("a wheel scroll holds message hover events, then moves hover once it settles", () => {
+ mock.timers.enable({ apis: ["setTimeout"] });
+ try {
+ const {
+ detach,
+ messages: [a, b, c],
+ } = attach("a", "b", "c");
+ enter(a);
+ thread.fire("wheel", { buttons: 0 });
+ thread.fire("scroll");
+ leave(a);
+ enter(b);
+ leave(b);
+ enter(c);
+ mock.timers.tick(100);
+ thread.fire("scroll");
+ mock.timers.tick(100);
+ assert.deepEqual([a.got, b.got, c.got], [["mouseenter"], [], []]);
+ mock.timers.tick(100);
+ assert.deepEqual(
+ [a.got, b.got, c.got],
+ [["mouseenter", "mouseleave"], [], ["mouseenter"]],
+ );
+ leave(c);
+ assert.deepEqual(c.got, ["mouseenter", "mouseleave"]);
+ detach();
+ } finally {
+ mock.timers.reset();
+ }
+});
+
+test("hover that has not moved by the time the scroll settles is left alone", () => {
+ mock.timers.enable({ apis: ["setTimeout"] });
+ try {
+ const {
+ detach,
+ messages: [a],
+ } = attach("a", "b");
+ enter(a);
+ thread.fire("wheel", { buttons: 0 });
+ thread.fire("scroll");
+ mock.timers.tick(200);
+ assert.deepEqual(a.got, ["mouseenter"]);
+ detach();
+ } finally {
+ mock.timers.reset();
+ }
+});
+
+test("a message hovered from mount, with no mouseenter, still loses hover after the scroll", () => {
+ mock.timers.enable({ apis: ["setTimeout"] });
+ try {
+ const {
+ detach,
+ messages: [a, b],
+ } = attach("a", "b");
+ a.hover = true;
+ thread.fire("wheel", { buttons: 0 });
+ thread.fire("scroll");
+ leave(a);
+ enter(b);
+ mock.timers.tick(200);
+ assert.deepEqual([a.got, b.got], [["mouseleave"], ["mouseenter"]]);
+ detach();
+ } finally {
+ mock.timers.reset();
+ }
+});
+
+test("programmatic scrolls (follow-to-bottom) and button-held wheels keep hover events", () => {
+ const {
+ detach,
+ messages: [a, b],
+ } = attach("a", "b");
+ thread.fire("scroll");
+ enter(a);
+ thread.fire("wheel", { buttons: 1 });
+ thread.fire("scroll");
+ leave(a);
+ enter(b);
+ assert.deepEqual(
+ [a.got, b.got],
+ [["mouseenter", "mouseleave"], ["mouseenter"]],
+ );
+ detach();
+});
+
+test("a selection drag passes through during an active wheel tail", () => {
+ mock.timers.enable({ apis: ["setTimeout"] });
+ try {
+ const {
+ detach,
+ messages: [a, b],
+ } = attach("a", "b");
+ enter(a);
+ thread.fire("wheel", { buttons: 0 });
+ thread.fire("scroll");
+ leave(a, 1);
+ enter(b, 1);
+ assert.deepEqual(
+ [a.got, b.got],
+ [["mouseenter", "mouseleave"], ["mouseenter"]],
+ );
+ mock.timers.tick(200);
+ assert.deepEqual(
+ [a.got, b.got],
+ [["mouseenter", "mouseleave"], ["mouseenter"]],
+ );
+ detach();
+ } finally {
+ mock.timers.reset();
+ }
+});
+
+test("detaching mid-scroll settles hover and stops listening", () => {
+ mock.timers.enable({ apis: ["setTimeout"] });
+ try {
+ const {
+ detach,
+ messages: [a, b],
+ } = attach("a", "b");
+ enter(a);
+ thread.fire("wheel", { buttons: 0 });
+ thread.fire("scroll");
+ leave(a);
+ enter(b);
+ detach();
+ assert.deepEqual(
+ [a.got, b.got],
+ [["mouseenter", "mouseleave"], ["mouseenter"]],
+ );
+ assert.equal(thread.listeners.size, 0);
+ } finally {
+ mock.timers.reset();
+ }
+});
+
+test("the thread attaches it to its viewport", () => {
+ assert.match(
+ readSrc("components/assistant-ui/thread.tsx"),
+ /return attachWheelHoverSuppression\(viewportEl\);/,
+ );
+});