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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
studio: reduce main-thread work in Deep Research and tooltips (#8525)
Maheswar Kumara14c86e61cce
diff --git a/studio/frontend/src/components/ui/tooltip.tsx b/studio/frontend/src/components/ui/tooltip.tsxindex 761ed205dd5..9a4ba9c48c4 100644--- a/studio/frontend/src/components/ui/tooltip.tsx+++ b/studio/frontend/src/components/ui/tooltip.tsx@@ -24,13 +24,13 @@ const TooltipTriggerElementCtx = createContext<(element: HTMLElement | null) =>// Radix sets body pointer-events to none while a modal layer is up. That is also when a hovered// trigger stops receiving pointerleave, so a tooltip already on screen hangs over the dialog-// with nothing able to close it. One observer serves every tooltip.+// with nothing able to close it. Two shared observers serve every tooltip.let modalLayerUp = false;const modalLayerListeners = new Set<() => void>();-let modalLayerObserver: MutationObserver | null = null;+let bodyLayerObserver: MutationObserver | null = null;+let stackedLayerObserver: MutationObserver | null = null;-function readModalLayer(): void {- modalLayerUp = document.body.style.pointerEvents === "none";+function notifyModalLayer(): void {for (const listener of modalLayerListeners) listener();}@@ -41,7 +41,7 @@ function readPointerEvents(style: string | null): string {);}-function readRelevantLayerMutations(records: MutationRecord[]): void {+function readStackedLayerMutations(records: MutationRecord[]): void {const pointerEventsChanged = records.some((record) =>readPointerEvents(record.oldValue) !==@@ -49,18 +49,41 @@ function readRelevantLayerMutations(records: MutationRecord[]): void {(record.target as Element).getAttribute?.("style") ?? null,),);- if (pointerEventsChanged) readModalLayer();+ if (pointerEventsChanged) notifyModalLayer();+}++// stacking only matters while a modal is up; otherwise this fires on every animated inline style.+function syncStackedLayerObserver(): void {+ if (!modalLayerUp) {+ stackedLayerObserver?.disconnect();+ stackedLayerObserver = null;+ return;+ }+ if (stackedLayerObserver) return;+ stackedLayerObserver = new MutationObserver(readStackedLayerMutations);+ stackedLayerObserver.observe(document.body, {+ attributes: true,+ attributeFilter: ["style"],+ attributeOldValue: true,+ subtree: true,+ });+}++function readModalLayer(): void {+ const next = document.body.style.pointerEvents === "none";+ if (next === modalLayerUp) return;+ modalLayerUp = next;+ syncStackedLayerObserver();+ notifyModalLayer();}function subscribeModalLayer(listener: () => void): () => void {modalLayerListeners.add(listener);- if (!modalLayerObserver && typeof MutationObserver !== "undefined") {- modalLayerObserver = new MutationObserver(readRelevantLayerMutations);- modalLayerObserver.observe(document.body, {+ if (!bodyLayerObserver && typeof MutationObserver !== "undefined") {+ bodyLayerObserver = new MutationObserver(readModalLayer);+ bodyLayerObserver.observe(document.body, {attributes: true,attributeFilter: ["style"],- attributeOldValue: true,- subtree: true,});readModalLayer();}diff --git a/studio/frontend/src/features/chat/components/research-activity-panel.tsx b/studio/frontend/src/features/chat/components/research-activity-panel.tsxindex 647633ac474..526ac6e6c90 100644--- a/studio/frontend/src/features/chat/components/research-activity-panel.tsx+++ b/studio/frontend/src/features/chat/components/research-activity-panel.tsx@@ -79,6 +79,9 @@ const terminalStatuses = new Set<ResearchRunStatus>([]);const ACTIVITY_FOLLOW_SETTLE_MS = 450;const ACTIVITY_BOTTOM_THRESHOLD_PX = 24;+// 2px, not 1, matching use-intent-aware-autoscroll: HiDPI subpixel rounding leaves a fractional+// gap that a 1px threshold reads as unpinned, which would keep the follow loop running forever.+const ACTIVITY_PINNED_THRESHOLD_PX = 2;function useResearchActivityScroll(runId: string) {const viewportRef = useRef<HTMLDivElement>(null);@@ -95,6 +98,9 @@ function useResearchActivityScroll(runId: string) {let lastScrollTop = element.scrollTop;let followUntil = performance.now() + ACTIVITY_FOLLOW_SETTLE_MS;let animationFrame: number | null = null;+ let settleTimer: number | null = null;+ let settleCheckDue = false;+ let layoutChanged = true;const distanceFromBottom = () =>Math.max(@@ -106,24 +112,56 @@ function useResearchActivityScroll(runId: string) {const requestTick = () => {if (animationFrame === null) animationFrame = requestAnimationFrame(tick);};+ // A reflow with no DOM mutation (a `font-display: swap` webfont landing, say) reaches neither+ // observer, so the rest of the window is covered by one deferred check rather than every frame.+ const scheduleSettleCheck = () => {+ if (settleTimer !== null) return;+ const remaining = followUntil - performance.now();+ if (remaining <= 0) return;+ settleTimer = window.setTimeout(() => {+ settleTimer = null;+ // The timer lands on the deadline and its tick a frame later, so the window has closed by+ // then; this grants that tick one last follow pass rather than dropping it to the reconcile.+ settleCheckDue = true;+ requestTick();+ }, remaining);+ };const tick = () => {animationFrame = null;- if (!detached && performance.now() < followUntil) {- if (distanceFromBottom() > 1) element.scrollTop = element.scrollHeight;+ const settling = settleCheckDue;+ settleCheckDue = false;+ if (!detached && (settling || performance.now() < followUntil)) {+ const pinned = distanceFromBottom() <= ACTIVITY_PINNED_THRESHOLD_PX;+ if (!pinned) element.scrollTop = element.scrollHeight;updateAtBottom(true);- requestTick();+ // Chaining on the window alone forced a layout every frame for the whole run; growth that+ // leaves the view unpinned is the signal, and a quiet frame defers to the settle check.+ if (layoutChanged || !pinned) {+ layoutChanged = false;+ requestTick();+ return;+ }+ scheduleSettleCheck();return;}updateAtBottom(distanceFromBottom() <= ACTIVITY_BOTTOM_THRESHOLD_PX);};const followLayout = () => {if (detached) return;+ layoutChanged = true;followUntil = performance.now() + ACTIVITY_FOLLOW_SETTLE_MS;requestTick();};const detach = () => {detached = true;followUntil = 0;+ // A settle check queued by the last quiet frame would otherwise fire mid-scroll and reconcile+ // isAtBottom back to true whenever the user has moved less than the bottom threshold.+ if (settleTimer !== null) {+ window.clearTimeout(settleTimer);+ settleTimer = null;+ }+ settleCheckDue = false;updateAtBottom(false);};const innerScrollWillConsumeUpward = (target: EventTarget | null) => {@@ -216,6 +254,7 @@ function useResearchActivityScroll(runId: string) {return () => {if (animationFrame !== null) cancelAnimationFrame(animationFrame);+ if (settleTimer !== null) window.clearTimeout(settleTimer);resizeObserver.disconnect();mutationObserver.disconnect();element.removeEventListener("scroll", onScroll);