Skip to content

Commit 5b6ac19

Browse files
committed
Fix height computation
1 parent b6bf0df commit 5b6ac19

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

  • examples/customer-segmentation-server/src

examples/customer-segmentation-server/src/mcp-app.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,24 @@ app.onhostcontextchanged = (params) => {
508508
if (params.safeAreaInsets) {
509509
applySafeAreaInsets(params.safeAreaInsets);
510510
}
511+
// Update container height based on containerDimensions from host
512+
// This ensures the chart resizes correctly during transitions
513+
if (params.containerDimensions) {
514+
const mainEl = document.querySelector(".main") as HTMLElement | null;
515+
if (mainEl) {
516+
if ("height" in params.containerDimensions) {
517+
// If height is fixed, take up all the height
518+
mainEl.style.height = "100vh";
519+
} else if ("maxHeight" in params.containerDimensions) {
520+
// If height is variable, let the rest of the css determine the height
521+
mainEl.style.height = "";
522+
}
523+
// Resize chart after container dimensions change
524+
if (state.chart) {
525+
state.chart.resize();
526+
}
527+
}
528+
}
511529
// Recreate chart to pick up new colors
512530
if (state.chart && (params.theme || params.styles?.variables)) {
513531
state.chart.destroy();
@@ -533,6 +551,13 @@ app.connect().then(() => {
533551
if (ctx?.safeAreaInsets) {
534552
applySafeAreaInsets(ctx.safeAreaInsets);
535553
}
554+
// Apply initial container dimensions
555+
if (ctx?.containerDimensions) {
556+
const mainEl = document.querySelector(".main") as HTMLElement | null;
557+
if (mainEl && "height" in ctx.containerDimensions) {
558+
mainEl.style.height = `${ctx.containerDimensions.height}px`;
559+
}
560+
}
536561
});
537562

538563
// Fetch data after connection

0 commit comments

Comments
 (0)