From 0c1b8f1d1503953d23eef50d100b90fccbcdf739 Mon Sep 17 00:00:00 2001 From: Mangesh Raut <95149253+mangeshraut712@users.noreply.github.com> Date: Sun, 29 Nov 2026 22:48:12 +0530 Subject: [PATCH 1/2] Report MCP App size changes when portals open --- src/app.ts | 48 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/src/app.ts b/src/app.ts index be5cbb2cb..eb98f58aa 100644 --- a/src/app.ts +++ b/src/app.ts @@ -2176,17 +2176,16 @@ export class App extends Protocol { * ``` */ setupSizeChangedNotifications() { - let scheduled = false; + let frameId: number | undefined; let lastWidth = 0; let lastHeight = 0; const sendBodySizeChanged = () => { - if (scheduled) { + if (frameId !== undefined) { return; } - scheduled = true; - requestAnimationFrame(() => { - scheduled = false; + frameId = requestAnimationFrame(() => { + frameId = undefined; const html = document.documentElement; // Measure actual content height by temporarily overriding html sizing. @@ -2201,7 +2200,29 @@ export class App extends Protocol { // destroying their scroll positions. const originalHeight = html.style.height; html.style.height = "max-content"; - const height = Math.ceil(html.getBoundingClientRect().height); + const body = document.body; + const rootRect = html.getBoundingClientRect(); + // Body overflow includes positioned descendants that do not grow either + // observed box. Avoid using the root scroll height, which can include + // the host's existing viewport height and prevent the view shrinking. + let overflowHeight = + body.scrollHeight > body.clientHeight + ? body.getBoundingClientRect().top - + rootRect.top + + body.scrollHeight + : 0; + // A portal positioned against the root may also be outside the body's + // scroll area. Include direct absolute children without counting fixed + // overlays or the viewport minimum in the root scroll height. + for (const child of Array.from(body.children)) { + if (getComputedStyle(child).position === "absolute") { + overflowHeight = Math.max( + overflowHeight, + child.getBoundingClientRect().bottom - rootRect.top, + ); + } + } + const height = Math.ceil(Math.max(rootRect.height, overflowHeight)); html.style.height = originalHeight; const width = Math.ceil(window.innerWidth); @@ -2222,7 +2243,20 @@ export class App extends Protocol { resizeObserver.observe(document.documentElement); resizeObserver.observe(document.body); - return () => resizeObserver.disconnect(); + // Portals can be inserted, removed, or toggled without a box resize. + // Observe only the body so the temporary html height does not reschedule us. + const mutationObserver = new MutationObserver(sendBodySizeChanged); + mutationObserver.observe(document.body, { + attributes: true, + childList: true, + subtree: true, + }); + + return () => { + resizeObserver.disconnect(); + mutationObserver.disconnect(); + if (frameId !== undefined) cancelAnimationFrame(frameId); + }; } /** From d37c85394aa6b42685fc9eb0c2cac11ba62ddd4f Mon Sep 17 00:00:00 2001 From: Mangesh Raut <95149253+mangeshraut712@users.noreply.github.com> Date: Mon, 30 Nov 2026 15:23:47 +0530 Subject: [PATCH 2/2] Count absolute popovers inside zero-height portal containers Mantine renders a popover as an absolute element inside a plain, zero-height div appended to the body. That element is neither a direct absolute child of the body nor part of the body's scroll overflow, so opening it sent no new height. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01NMDiXp8DnMSF8zyzneEdj3 --- src/app.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/app.ts b/src/app.ts index eb98f58aa..52687eed3 100644 --- a/src/app.ts +++ b/src/app.ts @@ -2212,14 +2212,25 @@ export class App extends Protocol { body.scrollHeight : 0; // A portal positioned against the root may also be outside the body's - // scroll area. Include direct absolute children without counting fixed - // overlays or the viewport minimum in the root scroll height. + // scroll area: either an absolute child of the body, or an absolute + // element inside a zero-height portal container (as Mantine renders + // popovers). Fixed overlays and the root scroll height, which includes + // the viewport minimum, are not counted. + const includeBottom = (element: Element) => { + overflowHeight = Math.max( + overflowHeight, + element.getBoundingClientRect().bottom - rootRect.top, + ); + }; for (const child of Array.from(body.children)) { if (getComputedStyle(child).position === "absolute") { - overflowHeight = Math.max( - overflowHeight, - child.getBoundingClientRect().bottom - rootRect.top, - ); + includeBottom(child); + } else if (child.getBoundingClientRect().height === 0) { + for (const element of Array.from(child.querySelectorAll("*"))) { + if (getComputedStyle(element).position === "absolute") { + includeBottom(element); + } + } } } const height = Math.ceil(Math.max(rootRect.height, overflowHeight));