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: remeasure the overlay stack when its content resizes in place (#8315)
Daniel Han5a8476694170
diff --git a/studio/frontend/src/features/settings/stores/monitor-frame-store.ts b/studio/frontend/src/features/settings/stores/monitor-frame-store.tsindex efa8c8901ca..8f254a53cdf 100644--- a/studio/frontend/src/features/settings/stores/monitor-frame-store.ts+++ b/studio/frontend/src/features/settings/stores/monitor-frame-store.ts@@ -340,13 +340,54 @@ export function useStackGeometry(): StackPlacement {setNeededRoom((current) => (current === natural ? current : natural));};measure();- const observer = new ResizeObserver(measure);- observer.observe(node);- // A 0-height stack stays 0 as children come and go, so watch the child list too.- const mutations = new MutationObserver(measure);+ // Every box inside the stack, not just the stack itself. At its cap the container's+ // border box does not move when its content grows, so a root-only observer never+ // fires for a release-note image finishing its load, and childList says nothing+ // either: the stack would keep the pre-load height and stay clipped.+ // Height only. The llama.cpp update banner animates its progress bar's width on every+ // frame, and that bar is inside this stack, so an unfiltered observer would remeasure+ // at ~60Hz for a stack whose height never moved, each one forcing a synchronous layout+ // to read scrollHeight with the cap lifted.+ const heights = new WeakMap<Element, number>();+ const observer = new ResizeObserver((entries) => {+ let moved = false;+ for (const entry of entries) {+ const height =+ entry.borderBoxSize?.[0]?.blockSize ?? entry.contentRect.height;+ if (heights.get(entry.target) !== height) {+ heights.set(entry.target, height);+ moved = true;+ }+ }+ if (moved) measure();+ });+ const observed = new Set<Element>();+ const syncObserved = () => {+ const wanted = new Set<Element>([node, ...node.querySelectorAll("*")]);+ for (const element of observed) {+ if (!wanted.has(element)) {+ observer.unobserve(element);+ observed.delete(element);+ }+ }+ for (const element of wanted) {+ if (!observed.has(element)) {+ observer.observe(element);+ observed.add(element);+ }+ }+ };+ syncObserved();+ // A 0-height stack stays 0 as children come and go, so watch the child list too, and+ // observe whatever just arrived.+ const mutations = new MutationObserver(() => {+ syncObserved();+ measure();+ });mutations.observe(node, { childList: true, subtree: true });return () => {observer.disconnect();+ observed.clear();mutations.disconnect();};}, []);diff --git a/studio/frontend/tests/monitor-stack-inset.test.ts b/studio/frontend/tests/monitor-stack-inset.test.tsindex 120f54e9926..32c90649787 100644--- a/studio/frontend/tests/monitor-stack-inset.test.ts+++ b/studio/frontend/tests/monitor-stack-inset.test.ts@@ -317,7 +317,7 @@ test("the height is measured with the hook's own cap lifted", async () => {);const measure = source.slice(source.indexOf("const measure = () => {"),- source.indexOf("observer.observe(node)"),+ source.indexOf("const observer = new ResizeObserver"),);assert.ok(measure, "the measure callback moved");assert.match(@@ -434,3 +434,59 @@ test("no pairing produces an overlap or an unusable cap", () => {}}});++// At its cap the stack's border box does not move when its content grows, so neither a+// root-only ResizeObserver nor a childList watcher hears an image finish loading inside an+// expanded release note, and the stack keeps the pre-load height and stays clipped.+test("every box inside the stack is observed, not just the stack", async () => {+ const source = await readFile(+ new URL(+ "../src/features/settings/stores/monitor-frame-store.ts",+ import.meta.url,+ ),+ "utf8",+ );+ const wiring = source.slice(source.indexOf("const observer = new ResizeObserver"));+ assert.ok(+ !/observer\.observe\(node\)/.test(wiring),+ "the root alone is observed, so an intrinsic descendant resize is missed",+ );+ assert.match(+ wiring,+ /querySelectorAll\("\*"\)/,+ "the descendants are never enumerated, so none of them is observed",+ );+ // A changed subtree has to be re-observed, or a banner arriving after mount is missed.+ const onMutation = wiring.slice(wiring.indexOf("new MutationObserver"));+ assert.match(onMutation, /syncObserved\(\)/, "the observed set is not resynced");+ // And unobserved on the way out, or a detached node keeps the observer alive.+ assert.match(wiring, /observer\.unobserve\(/, "nothing is ever unobserved");+});++// The llama.cpp update banner animates its progress bar's width every frame, inside this+// same stack. Observing descendants without filtering therefore remeasures at ~60Hz for a+// stack whose height never moved, and each remeasure lifts the cap and reads scrollHeight,+// which forces a synchronous layout.+test("a width-only animation does not remeasure the stack", async () => {+ const source = await readFile(+ new URL(+ "../src/features/settings/stores/monitor-frame-store.ts",+ import.meta.url,+ ),+ "utf8",+ );+ const wiring = source.slice(+ source.indexOf("const observer = new ResizeObserver"),+ source.indexOf("const observed = new Set<Element>()"),+ );+ assert.ok(+ !/new ResizeObserver\(measure\)/.test(wiring),+ "every observed resize remeasures, width-only ones included",+ );+ assert.match(wiring, /blockSize/, "the entry's height is never read");+ assert.match(+ wiring,+ /if \(moved\) measure\(\)/,+ "measure runs whether or not a height moved",+ );+});