Skip to content

Commit 33fa759

Browse files
committed
Update onsizechange to onheightchange
1 parent ced5954 commit 33fa759

File tree

23 files changed

+126
-151
lines changed

23 files changed

+126
-151
lines changed

examples/basic-host/src/implementation.ts

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -244,38 +244,23 @@ export function newAppBridge(serverInfo: ServerInfo, iframe: HTMLIFrameElement):
244244
log.info("Log message from MCP App:", params);
245245
};
246246

247-
appBridge.onsizechange = async ({ width, height }) => {
248-
// The MCP App has requested a `width` and `height`, but if
249-
// `box-sizing: border-box` is applied to the outer iframe element, then we
250-
// must add border thickness to `width` and `height` to compute the actual
251-
// necessary width and height (in order to prevent a resize feedback loop).
247+
appBridge.onheightchange = ({ height }) => {
248+
// The MCP App has requested a `height`, but if `box-sizing: border-box` is
249+
// applied to the outer iframe element, then we must add border thickness to
250+
// `height` to compute the actual necessary height (to prevent a resize
251+
// feedback loop).
252252
const style = getComputedStyle(iframe);
253253
const isBorderBox = style.boxSizing === "border-box";
254254

255-
// Animate the change for a smooth transition.
256-
const from: Keyframe = {};
257-
const to: Keyframe = {};
258-
259-
if (width !== undefined) {
260-
if (isBorderBox) {
261-
width += parseFloat(style.borderLeftWidth) + parseFloat(style.borderRightWidth);
262-
}
263-
// Use min-width instead of width to allow responsive growing.
264-
// With auto-resize (the default), the app reports its minimum content
265-
// width; we honor that as a floor but allow the iframe to expand when
266-
// the host layout allows. And we use `min(..., 100%)` so that the iframe
267-
// shrinks with its container.
268-
from.minWidth = `${iframe.offsetWidth}px`;
269-
iframe.style.minWidth = to.minWidth = `min(${width}px, 100%)`;
270-
}
271-
if (height !== undefined) {
272-
if (isBorderBox) {
273-
height += parseFloat(style.borderTopWidth) + parseFloat(style.borderBottomWidth);
274-
}
275-
from.height = `${iframe.offsetHeight}px`;
276-
iframe.style.height = to.height = `${height}px`;
255+
if (isBorderBox) {
256+
height += parseFloat(style.borderTopWidth) + parseFloat(style.borderBottomWidth);
277257
}
278258

259+
// Animate the change for a smooth transition.
260+
const from: Keyframe = { height: `${iframe.offsetHeight}px` };
261+
const to: Keyframe = { height: `${height}px` };
262+
iframe.style.height = `${height}px`;
263+
279264
iframe.animate([from, to], { duration: 300, easing: "ease-out" });
280265
};
281266

examples/basic-server-react/src/global.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
html, body {
66
font-family: system-ui, -apple-system, sans-serif;
77
font-size: 1rem;
8+
margin: 0;
9+
padding: 0;
10+
width: 100%;
811
}
912

1013
code {

examples/basic-server-react/src/mcp-app.module.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
--color-notice-bg: #eff6ff;
55

66
width: 100%;
7-
max-width: 425px;
87
box-sizing: border-box;
98

109
> * {

examples/basic-server-vanillajs/src/global.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
html, body {
66
font-family: system-ui, -apple-system, sans-serif;
77
font-size: 1rem;
8+
margin: 0;
9+
padding: 0;
10+
width: 100%;
811
}
912

1013
code {

examples/basic-server-vanillajs/src/mcp-app.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
--color-notice-bg: #eff6ff;
55

66
width: 100%;
7-
max-width: 425px;
87
box-sizing: border-box;
98

109
> * {

examples/budget-allocator-server/src/global.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ html, body {
77
font-size: 14px;
88
margin: 0;
99
padding: 0;
10+
width: 100%;
1011
}
1112

1213
code {

examples/cohort-heatmap-server/src/global.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ html, body {
77
font-size: 1rem;
88
margin: 0;
99
padding: 0;
10+
width: 100%;
1011
}

examples/customer-segmentation-server/src/global.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
html, body {
66
font-family: system-ui, -apple-system, sans-serif;
77
font-size: 1rem;
8+
margin: 0;
9+
padding: 0;
10+
width: 100%;
811
}
912

1013
code {

examples/scenario-modeler-server/src/global.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ html, body {
77
padding: 0;
88
font-family: system-ui, -apple-system, sans-serif;
99
font-size: 1rem;
10+
width: 100%;
1011
}
1112

1213
code {

examples/system-monitor-server/src/global.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
html, body {
66
font-family: system-ui, -apple-system, sans-serif;
77
font-size: 1rem;
8+
margin: 0;
9+
padding: 0;
10+
width: 100%;
811
}
912

1013
code {

0 commit comments

Comments
 (0)