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: keep code colour while scrolling long chats (#14242)

Daniel Han8de2de25bbd3
diff --git a/studio/frontend/scripts/check-bundle-budget.ts b/studio/frontend/scripts/check-bundle-budget.ts
index 4504db9e8b4..a09f9d3a30f 100644
--- a/studio/frontend/scripts/check-bundle-budget.ts
+++ b/studio/frontend/scripts/check-bundle-budget.ts
@@ -252,8 +252,8 @@ export const BUDGET = {
// raw, 2,054,190 -> 2,054,583 B transfer against a33463fb16, one machine and build, Node 24, chunk count
// unchanged at 96): the refresh retry and outcome live in features/auth/api.ts, which every authFetch imports.
// Raised by that growth, to the measured build plus the same 160 B raw / 189 B transfer margin.
- // Chunked fence lines, hoisted line colour, the progressive highlight queue, pointer state and the
- // scrollbar guard for the line window (#13919) add 11,012 B raw / 3,984 B transfer (6,826,518 ->
+ // Chunked fence lines, hoisted line colour, the progressive highlight queue and pointer state
+ // (#13919) add 11,012 B raw / 3,984 B transfer (6,826,518 ->
// 6,837,530 B raw, 2,054,604 -> 2,058,588 B transfer against ffd6c3033, one machine and build, Node 24,
// chunk count unchanged at 96), all in the eager chat chunk the fences render from. Raised to that
// build plus the same 160 B raw / 189 B transfer margin.
diff --git a/studio/frontend/src/components/assistant-ui/code-fence-defer.tsx b/studio/frontend/src/components/assistant-ui/code-fence-defer.tsx
index 3b4320a8995..2f0e80df348 100644
--- a/studio/frontend/src/components/assistant-ui/code-fence-defer.tsx
+++ b/studio/frontend/src/components/assistant-ui/code-fence-defer.tsx
@@ -55,7 +55,6 @@ import {
lineRendered,
pinBoundaryLines,
samePins,
- onScrollbar,
OVERSCAN_VIEWPORTS,
plainLineText,
selectLineWindow,
@@ -1063,7 +1062,6 @@ let frameRects: Map<Element, DOMRect> | null = null;
let frameFlying: Map<Element | null, boolean> | null = null;
let frameSettle = false;
let pointerHeld: Node | null = null;
-let barHeld: HTMLElement | null = null;
let heldLastFrame = false;
let frameSelection: { read: boolean; value: Selection | null } | null = null;
const scrollerMotion = new WeakMap<Element, { top: number; at: number }>();
@@ -1095,27 +1093,8 @@ const selectionDuringFrame = (): Selection | null => {
return frameSelection.value;
};
-// A thumb press targets the scroller, an ancestor of the fence body, so `pointerHeld` misses it and
-// the window would move on every frame of the drag; hold it until release instead.
-const scrollbarOf = (event: PointerEvent): HTMLElement | null => {
- const target = event.target;
- if (!(target instanceof HTMLElement)) return null;
- const spot = {
- offsetX: event.offsetX,
- offsetY: event.offsetY,
- clientWidth: target.clientWidth,
- clientHeight: target.clientHeight,
- };
- return onScrollbar(spot) && isScrollable(target) ? target : null;
-};
-
-const draggingDuringFrame = (
- body: HTMLElement,
- scroller: HTMLElement | null,
-): boolean => {
- const held =
- (pointerHeld !== null && body.contains(pointerHeld))
- || (barHeld !== null && barHeld === scroller);
+const draggingDuringFrame = (body: HTMLElement): boolean => {
+ const held = pointerHeld !== null && body.contains(pointerHeld);
if (held) heldLastFrame = true;
return held;
};
@@ -1415,13 +1394,11 @@ const scheduleRemeasure = (): void => {
const onPointerDown = (event: PointerEvent): void => {
if (event.pointerType === "touch" || event.button !== 0) return;
pointerHeld = event.target instanceof Node ? event.target : null;
- barHeld = scrollbarOf(event);
};
const releasePointer = (): void => {
- if (pointerHeld === null && barHeld === null) return;
+ if (pointerHeld === null) return;
pointerHeld = null;
- barHeld = null;
if (heldLastFrame) scheduleRemeasure();
};
@@ -1496,7 +1473,6 @@ const unwatchWindows = (): void => {
findBarObserver?.disconnect();
findBarObserver = null;
pointerHeld = null;
- barHeld = null;
heldLastFrame = false;
if (windowFrame !== 0) {
cancelAnimationFrame(windowFrame);
@@ -1712,7 +1688,7 @@ function useLineWindow(
return;
}
if (current.current !== null && flyingDuringFrame(known.scroller, viewportHeight)) return;
- if (current.current !== null && draggingDuringFrame(body, known.scroller)) return;
+ if (current.current !== null && draggingDuringFrame(body)) return;
const next = selectLineWindow({
lineCount: lines.current,
lineHeight: known.lineHeight,
diff --git a/studio/frontend/src/components/assistant-ui/code-fence-mode.ts b/studio/frontend/src/components/assistant-ui/code-fence-mode.ts
index d7a740c15d0..c3f56c67d42 100644
--- a/studio/frontend/src/components/assistant-ui/code-fence-mode.ts
+++ b/studio/frontend/src/components/assistant-ui/code-fence-mode.ts
@@ -7,11 +7,11 @@
* `node --experimental-strip-types`, which cannot load JSX. Every row below is RUN by
* `tests/code-fence-mode.test.ts` rather than checked by regexes over the source.
* "off" every fence is highlighted at mount. What shipped before `defer` became default.
- * "defer" An unreached fence is a plain shell and is never tokenized.
+ * "defer" SHIP DEFAULT. An unreached fence is a plain shell and is never tokenized.
* "tokenize" MEASUREMENT ONLY. Same plain shell, but the highlighter is still driven over the
* source and the result thrown away.
* "window" "defer", plus a LINE WINDOW inside a fence past `WINDOW_CAP_LINES`: off-screen
- * lines render their text as one node instead of their token spans. SHIP DEFAULT.
+ * lines render their text as one node instead of their token spans. Opt-in only.
* It is a superset of "defer": under the cap the two render the same DOM, so an
* A/B between them isolates the window and nothing else.
* `tokenize` is not a shipping mode. `defer` removes the spans AND the tokenizer work that makes
@@ -23,8 +23,8 @@
*/
export type FenceMode = "off" | "defer" | "tokenize" | "window";
-/** Moving this line is the whole of "turn deferral on by default"; every override still works. */
-export const SHIP_DEFAULT: FenceMode = "window";
+// Keep highlighted spans stable: line-window updates can stall Chrome during rapid scrollbar drags.
+export const SHIP_DEFAULT: FenceMode = "defer";
/**
* AN UNSET FLAG AND AN UNRECOGNISED ONE DO NOT RESOLVE TO THE SAME MODE. Unset means an install
diff --git a/studio/frontend/src/components/assistant-ui/code-fence-window.ts b/studio/frontend/src/components/assistant-ui/code-fence-window.ts
index 2fe31709280..bc45bf9f157 100644
--- a/studio/frontend/src/components/assistant-ui/code-fence-window.ts
+++ b/studio/frontend/src/components/assistant-ui/code-fence-window.ts
@@ -32,18 +32,6 @@ export const OVERSCAN_VIEWPORTS = 1;
// boundaries, the thrash that killed the earlier bidirectional gate.
export const HYSTERESIS_VIEWPORTS = 0.5;
-// `offsetX`/`offsetY` are from the padding box, so only a scrollbar press lands at or past the
-// client size.
-export type PointerSpot = {
- offsetX: number;
- offsetY: number;
- clientWidth: number;
- clientHeight: number;
-};
-
-export const onScrollbar = (spot: PointerSpot): boolean =>
- spot.offsetX >= spot.clientWidth || spot.offsetY >= spot.clientHeight;
-
export type WindowGeometry = {
lineCount: number;
/** MEASURED from the rendered block, never assumed. */
diff --git a/studio/frontend/tests/code-fence-mode.test.ts b/studio/frontend/tests/code-fence-mode.test.ts
index d4158ce5e23..43226d8e5b4 100644
--- a/studio/frontend/tests/code-fence-mode.test.ts
+++ b/studio/frontend/tests/code-fence-mode.test.ts
@@ -20,12 +20,12 @@ import { readSrc } from "./helpers/kit.ts";
* working in BOTH directions. A truth table nobody executes is not evidence of that.
*/
-test("an install that has never set the flag gets the ship default", () => {
- assert.equal(SHIP_DEFAULT, "window", "the ship default is the windowed deferral");
- assert.equal(resolveFenceMode(undefined, ""), "window");
+test("the default defers highlighting without moving line windows during scroll", () => {
+ assert.equal(SHIP_DEFAULT, "defer");
+ assert.equal(resolveFenceMode(undefined, ""), "defer");
});
-test("the plain deferral stays reachable as the ablation arm", () => {
+test("explicit deferral and windowing overrides remain available", () => {
assert.equal(resolveFenceMode(undefined, "defer"), "defer");
assert.equal(resolveFenceMode("defer", ""), "defer");
assert.equal(resolveFenceMode(true, ""), "defer");
diff --git a/studio/frontend/tests/code-fence-print.test.ts b/studio/frontend/tests/code-fence-print.test.ts
index 97d8316eda5..0b6cdf639d6 100644
--- a/studio/frontend/tests/code-fence-print.test.ts
+++ b/studio/frontend/tests/code-fence-print.test.ts
@@ -50,7 +50,7 @@ test("a drag freezes the line window, and a selection pins only the lines holdin
const defer = readSrc("components/assistant-ui/code-fence-defer.tsx");
const measure = defer.slice(defer.indexOf("measure.current = () => {"), defer.indexOf("useLayoutEffect(() => {", defer.indexOf("measure.current = () => {")));
const flying = measure.indexOf("flyingDuringFrame(");
- const dragging = measure.indexOf("if (current.current !== null && draggingDuringFrame(body, known.scroller)) return;");
+ const dragging = measure.indexOf("if (current.current !== null && draggingDuringFrame(body)) return;");
assert.ok(flying >= 0 && dragging > flying && dragging < measure.indexOf("selectLineWindow({"));
assert.ok(measure.indexOf("pinBoundaryLines(") > measure.indexOf("selectLineWindow({"), "the window keeps following the reader while the boundary lines stay as they were");
assert.match(measure, /if \(next === current\.current && samePins\(pins, pinned\.current\)\) return;/);
diff --git a/studio/frontend/tests/code-fence-window.test.ts b/studio/frontend/tests/code-fence-window.test.ts
index 05969be74f4..cb61bc39ab0 100644
--- a/studio/frontend/tests/code-fence-window.test.ts
+++ b/studio/frontend/tests/code-fence-window.test.ts
@@ -9,7 +9,6 @@ import {
HYSTERESIS_VIEWPORTS,
lineIsWindowed,
lineRendered,
- onScrollbar,
pinBoundaryLines,
samePins,
OVERSCAN_VIEWPORTS,
@@ -204,15 +203,3 @@ test("a selection boundary line keeps its rendering while the window moves on",
assert.equal(samePins(null, null), true);
assert.equal(samePins(kept, null), false);
});
-
-test("a press on a scrollbar holds the line window, a press on content does not", () => {
- const box = { clientWidth: 800, clientHeight: 600 };
- assert.equal(onScrollbar({ ...box, offsetX: 799, offsetY: 300 }), false, "the last content column");
- assert.equal(onScrollbar({ ...box, offsetX: 800, offsetY: 300 }), true, "the vertical gutter a thumb drag uses");
- assert.equal(onScrollbar({ ...box, offsetX: 400, offsetY: 600 }), true, "the horizontal bar of a wide fence");
- assert.equal(onScrollbar({ ...box, offsetX: 0, offsetY: 0 }), false);
- const defer = readSrc("components/assistant-ui/code-fence-defer.tsx");
- assert.match(defer, /\|\| \(barHeld !== null && barHeld === scroller\)/, "a held scrollbar counts as a drag on its own scroller's fences");
- assert.match(defer, /barHeld = scrollbarOf\(event\);/);
- assert.match(defer, /if \(pointerHeld === null && barHeld === null\) return;\s*pointerHeld = null;\s*barHeld = null;/, "releasing either remeasures");
-});