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 mid-scroll code block work on WebKit, fixing the #16865 scroll regression (#17149)

Daniel Hanae176c8c18d9
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 70d318c264c..d30444fe0a1 100644
--- a/studio/frontend/src/components/assistant-ui/code-fence-defer.tsx
+++ b/studio/frontend/src/components/assistant-ui/code-fence-defer.tsx
@@ -1099,6 +1099,10 @@ const highlightResize = (): void => {
};
// Bounded entries ignore wheel and touch scrolling; the rest still wait for the reader to stop.
+// Only with requestIdleCallback: without it (WebKit) each step is a timer inside the scroll that
+// swaps markup without colour (scroll cost rose about 6x).
+const MID_SCROLL_WORK = typeof window !== "undefined"
+ && typeof (window as { requestIdleCallback?: unknown }).requestIdleCallback === "function";
const highlightQuietIn = (duringScroll: boolean): number =>
Math.max(
duringScroll ? nonScrollInputQuietIn() : inputQuietIn(),
@@ -1166,7 +1170,7 @@ export function queueFenceWork(work: () => void): () => void {
const remove = highlightQueue.add(() => {
finish();
return true;
- }, finish, true);
+ }, finish, MID_SCROLL_WORK);
cancel = () => {
remove();
unwatchHighlighting();
@@ -1315,7 +1319,7 @@ function useFenceHighlightLimit(
);
setPrevious({ tokens, parked, progress: next });
return true;
- }, () => setPrevious({ tokens, parked, progress: null }), capped !== null);
+ }, () => setPrevious({ tokens, parked, progress: null }), capped !== null && MID_SCROLL_WORK);
return () => {
cancel();
unwatchHighlighting();
diff --git a/studio/frontend/tests/code-fence-body.test.ts b/studio/frontend/tests/code-fence-body.test.ts
index 20f95e506a6..c983509be64 100644
--- a/studio/frontend/tests/code-fence-body.test.ts
+++ b/studio/frontend/tests/code-fence-body.test.ts
@@ -408,7 +408,7 @@ test("a capped block colours only what is in view and a streaming one follows it
const hook = DEFER.slice(DEFER.indexOf("function useFenceHighlightLimit("), DEFER.indexOf("const READER_SCROLL_EVENTS"));
assert.match(hook, /const capped = innerLineWindow\(code\.current, body\);/);
assert.match(hook, /lineWindowColoured\(tokens, progress, capped\)/);
- assert.match(hook, /\}, \(\) => setPrevious\(\{ tokens, parked, progress: null \}\), capped !== null\);/);
+ assert.match(hook, /\}, \(\) => setPrevious\(\{ tokens, parked, progress: null \}\), capped !== null && MID_SCROLL_WORK\);/);
const pin = DEFER.slice(DEFER.indexOf("function usePinnedWhileStreaming("), DEFER.indexOf("export const FenceBody = memo("));
assert.match(pin, /if \(atBottom \|\| performance\.now\(\) - readerAt < 250\) following\.current = atBottom;/);
assert.match(pin, /body\.scrollTop = body\.scrollHeight;/);
diff --git a/studio/frontend/tests/desktop-webkit-paths.test.ts b/studio/frontend/tests/desktop-webkit-paths.test.ts
index 1a2fb0a99c8..54961308824 100644
--- a/studio/frontend/tests/desktop-webkit-paths.test.ts
+++ b/studio/frontend/tests/desktop-webkit-paths.test.ts
@@ -112,3 +112,12 @@ test("settled WebKitGTK fences only line-window themselves while code wrapping i
assert.match(defer, /const useCodeWrap = \(node: RefObject<Element \| null>\): boolean =>\s*useSyncExternalStore\(subscribeCodeWrap, \(\) => codeWrapOn\(node\.current\), \(\) => false\);/);
assert.match(defer, /attributeFilter: \["data-code-wrap", "data-wrap"\]/);
});
+
+test("without requestIdleCallback fence work waits for the reader to stop scrolling", () => {
+ const defer = readSrc("components/assistant-ui/code-fence-defer.tsx");
+ assert.match(defer, /const MID_SCROLL_WORK = typeof window !== "undefined"\s*&& typeof \(window as \{ requestIdleCallback\?: unknown \}\)\.requestIdleCallback === "function";/,
+ "WebKit has no requestIdleCallback: a mid-scroll step there is a timer inside the scroll, and the reach it makes swaps markup the worker has not coloured yet");
+ assert.match(defer, /const remove = highlightQueue\.add\(\(\) => \{\s*finish\(\);\s*return true;\s*\}, finish, MID_SCROLL_WORK\);/,
+ "a reach, a start and a worker answer run mid-scroll only where idle callbacks exist");
+ assert.match(defer, /capped !== null && MID_SCROLL_WORK\);/, "so do the lines in view inside a capped block");
+});