Skip to content

Commit 0c30294

Browse files
cliffhallclaude
andcommitted
review: guard 0-height size reports, distinct RendererFrame, shared payload type (PR #1656)
Address the claude[bot] review: - #1 (applied): handleSizeChange ignores a non-positive height — a view's ResizeObserver can transiently fire 0 pre-layout/teardown, which would collapse the frame; mirrors AppRenderer's 0×0 skip. Added a test. - #2 (applied): reinstate a distinct `RendererFrame` constant for the inner content-sized box so its role reads clearly vs. the outer RendererContainer. - #3 (declined + comment): keep carrying `appHeight` across maximize→restore — clearing it would flash the frame to full-card height until the next size-changed; the carry-over restores at the prior size. Documented. - #4 (applied): type handleSizeChange's param as AppBridgeEventMap["sizechange"] so the payload shape has a single source of truth with AppRenderer's prop. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01BrihGWcrM9JGRyu41nzZYw
1 parent 5688b6b commit 0c30294

2 files changed

Lines changed: 48 additions & 9 deletions

File tree

‎clients/web/src/components/screens/AppsScreen/AppsScreen.test.tsx‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,25 @@ describe("AppsScreen", () => {
349349
expect(frame.style.flexGrow).toBe("1");
350350
});
351351

352+
it("ignores a size-changed report with a non-positive height", async () => {
353+
const user = userEvent.setup();
354+
const { factory, emit } = createEventBridgeFactory();
355+
renderWithMantine(<ControlledAppsScreen bridgeFactory={factory} />);
356+
await user.click(screen.getByText("Ops Dashboard"));
357+
const frame = screen.getByTitle("Ops Dashboard")
358+
.parentElement as HTMLElement;
359+
await act(async () => {
360+
await Promise.resolve();
361+
await Promise.resolve();
362+
// A transient 0 (pre-layout / teardown) must not collapse the frame.
363+
emit("sizechange", { height: 0 });
364+
});
365+
expect(frame.style.flexGrow).toBe("1");
366+
// A subsequent positive report is honored.
367+
await act(async () => emit("sizechange", { height: 480 }));
368+
expect(frame.style.flexGrow).toBe("0");
369+
});
370+
352371
it("maximizes the frame when the view requests fullscreen via request-display-mode", async () => {
353372
const user = userEvent.setup();
354373
const { factory, bridges } = createEventBridgeFactory();

‎clients/web/src/components/screens/AppsScreen/AppsScreen.tsx‎

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ import {
1717
MdFullscreenExit,
1818
} from "react-icons/md";
1919
import type { Tool } from "@modelcontextprotocol/sdk/types.js";
20-
import type { McpUiDisplayMode } from "@modelcontextprotocol/ext-apps/app-bridge";
20+
import type {
21+
AppBridgeEventMap,
22+
McpUiDisplayMode,
23+
} from "@modelcontextprotocol/ext-apps/app-bridge";
2124
import {
2225
AppRenderer,
2326
type AppRendererHandle,
@@ -131,7 +134,7 @@ const HeaderActions = Group.withProps({
131134

132135
// The host-controlled box the running app sits within. Its size is driven by
133136
// the host's layout (window resize, sidebar toggle, maximize) and NOT by the
134-
// view's reported content height — that drives the inner box — so the
137+
// view's reported content height — that drives the inner RendererFrame — so the
135138
// renderer's containerDimensions observer can measure this element without
136139
// coupling host→view container size to view→host size-changed.
137140
const RendererContainer = Stack.withProps({
@@ -141,6 +144,15 @@ const RendererContainer = Stack.withProps({
141144
gap: 0,
142145
});
143146

147+
// The inner box that actually holds the iframe. Sized by the view-reported
148+
// content height (see `contentHeight`) and capped at the outer container.
149+
// Distinct from RendererContainer above so the two roles read clearly in JSX.
150+
const RendererFrame = Stack.withProps({
151+
miw: 0,
152+
mih: 0,
153+
gap: 0,
154+
});
155+
144156
const ContentStack = Stack.withProps({
145157
gap: "md",
146158
h: "100%",
@@ -180,9 +192,12 @@ export function AppsScreen({
180192
// nor surrounded by dead space. Width is left at the host-controlled
181193
// container width. The value is clamped to the available space by the
182194
// renderer frame's `mah` below, and ignored while maximized (the app fills
183-
// the screen instead).
184-
function handleSizeChange(size: { width?: number; height?: number }) {
185-
if (size.height != null) setAppHeight(size.height);
195+
// the screen instead). A non-positive height is ignored — a view's
196+
// ResizeObserver can transiently fire 0 before layout settles or during
197+
// teardown, which would otherwise collapse the frame (mirrors AppRenderer's
198+
// own 0×0 skip on the container side).
199+
function handleSizeChange(size: AppBridgeEventMap["sizechange"]) {
200+
if (size.height != null && size.height > 0) setAppHeight(size.height);
186201
}
187202

188203
// The app's display mode is derived from the existing maximized toggle.
@@ -264,6 +279,11 @@ export function AppsScreen({
264279

265280
// While maximized the app fills the screen, so the view-reported height is
266281
// ignored; otherwise we honor it (clamped to the card by the frame's `mah`).
282+
// `appHeight` is intentionally NOT cleared when toggling maximize: carrying
283+
// the last inline height across a maximize→restore means the frame restores
284+
// at its prior size immediately, rather than flashing to full-card height
285+
// (flex:1) for the frame or two until the view sends a fresh size-changed
286+
// after the `inline` host-context-changed.
267287
const contentHeight = maximized ? undefined : appHeight;
268288

269289
return (
@@ -335,10 +355,10 @@ export function AppsScreen({
335355
</HeaderRow>
336356
{running ? (
337357
// RendererContainer is the host-controlled box (its size only
338-
// changes with host layout); the inner Stack is sized by the
339-
// view's reported content height, capped at the container.
358+
// changes with host layout); the inner RendererFrame is sized by
359+
// the view's reported content height, capped at the container.
340360
<RendererContainer ref={rendererContainerRef}>
341-
<RendererContainer
361+
<RendererFrame
342362
flex={contentHeight != null ? "0 0 auto" : 1}
343363
h={contentHeight}
344364
mah="100%"
@@ -358,7 +378,7 @@ export function AppsScreen({
358378
containerRef={rendererContainerRef}
359379
ref={rendererRef}
360380
/>
361-
</RendererContainer>
381+
</RendererFrame>
362382
</RendererContainer>
363383
) : (
364384
// `isOpening` is always false here because `handleOpen`

0 commit comments

Comments
 (0)