Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 89 additions & 6 deletions specification/draft/apps.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,20 @@ interface HostContext {
displayMode?: "inline" | "fullscreen" | "pip";
/** Display modes the host supports */
availableDisplayModes?: string[];
/** Current and maximum dimensions available to the UI */
/** Container dimensions for the iframe. Specify either width or maxWidth, and either height or maxHeight. */
containerDimensions?: (
| { height: number } // If specified, container is fixed at this height
| { maxHeight?: number } // Otherwise, container height is determined by the UI height, up to this maximum height (if defined)
) & (
| { width: number } // If specified, container is fixed at this width
| { maxWidth?: number } // Otherwise, container width is determined by the UI width, up to this maximum width (if defined)
);
/** Host window viewport dimensions */
viewport?: {
width: number;
height: number;
maxHeight?: number;
maxWidth?: number;
/** Window viewport width in pixels. */
width?: number;
Copy link
Collaborator Author

@martinalong martinalong Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ochafik I realized that no matter what, we have to make this change (making these fields optional), which is is a minor breaking change

I don't think there's really a way around it if we want to adopt this new shape. Wdyt should be the plan here? I think we may as well just update it to the type i originally proposed and announce the next version will be a breaking change

/** Window viewport height in pixels. */
height?: number;
};
/** User's language/region preference (BCP 47, e.g., "en-US") */
locale?: string;
Expand Down Expand Up @@ -516,12 +524,87 @@ Example:
}
},
"displayMode": "inline",
"viewport": { "width": 400, "height": 300 }
"containerDimensions": { "width": 400, "maxHeight": 600 }
"viewport": { "width": 1920, "height": 1080 },
}
}
}
```

### Viewport and Dimensions

The `HostContext` provides two separate fields for sizing information:

- **`containerDimensions`**: The dimensions of the container that holds the app. This controls the actual space the app occupies within the host. Each dimension (height and width) operates independently and can be either **fixed** or **flexible**.

- **`viewport`**: The host window's dimensions (e.g., `window.innerWidth` and `window.innerHeight`). Apps can use this to make responsive layout decisions based on the overall screen size.

#### Dimension Modes

| Mode | Dimensions Field | Meaning |
|------|-----------------|---------|
| Fixed | `height` or `width` | Host controls the size. App should fill the available space. |
| Flexible | `maxHeight` or `maxWidth` | App controls the size, up to the specified maximum. |
| Unbounded | Field omitted | App controls the size with no limit. |

These modes can be combined independently. For example, a host might specify a fixed width but flexible height, allowing the app to grow vertically based on content.

#### App Behavior

Apps should check the containerDimensions configuration and apply appropriate CSS:

```typescript
// In the app's initialization
const containerDimensions = hostContext.containerDimensions;

if (containerDimensions) {
// Handle height
if ("height" in containerDimensions) {
// Fixed height: fill the container
document.documentElement.style.height = "100vh";
} else if ("maxHeight" in containerDimensions && containerDimensions.maxHeight) {
// Flexible with max: let content determine size, up to max
document.documentElement.style.maxHeight = `${containerDimensions.maxHeight}px`;
}
// If neither, height is unbounded

// Handle width
if ("width" in containerDimensions) {
// Fixed width: fill the container
document.documentElement.style.width = "100vw";
} else if ("maxWidth" in containerDimensions && containerDimensions.maxWidth) {
// Flexible with max: let content determine size, up to max
document.documentElement.style.maxWidth = `${containerDimensions.maxWidth}px`;
}
// If neither, width is unbounded
}

// Apps can also use viewport for additional data to make responsive layout decisions
const viewport = hostContext.viewport;
if (viewport?.width && viewport.width < 768) {
// Apply mobile-friendly layout
}
```

#### Host Behavior

When using flexible dimensions (no fixed `height` or `width`), hosts MUST listen for `ui/notifications/size-changed` notifications from the app and update the iframe dimensions accordingly:

```typescript
// Host listens for size changes from the app
bridge.onsizechange = ({ width, height }) => {
// Update iframe to match app's content size
if (width != null) {
iframe.style.width = `${width}px`;
}
if (height != null) {
iframe.style.height = `${height}px`;
}
};
```

Apps using the SDK automatically send size-changed notifications via ResizeObserver when `autoResize` is enabled (the default). The notifications are debounced and only sent when dimensions actually change.

### Theming

Hosts can optionally pass CSS custom properties via `HostContext.styles.variables` for visual cohesion with the host environment.
Expand Down
16 changes: 13 additions & 3 deletions src/app-bridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ describe("App <-> AppBridge integration", () => {
theme: "dark" as const,
locale: "en-US",
viewport: { width: 800, height: 600 },
containerDimensions: { width: 800, maxHeight: 600 },
};
const newBridge = new AppBridge(
createMockClient() as Client,
Expand Down Expand Up @@ -338,6 +339,7 @@ describe("App <-> AppBridge integration", () => {
theme: "light" as const,
locale: "en-US",
viewport: { width: 800, height: 600 },
containerDimensions: { width: 800, maxHeight: 600 },
};
const newBridge = new AppBridge(
createMockClient() as Client,
Expand All @@ -354,20 +356,28 @@ describe("App <-> AppBridge integration", () => {
newBridge.sendHostContextChange({ theme: "dark" });
await flush();

// Send another partial update: only viewport changes
// Send another partial update: only viewport and containerDimensions change
newBridge.sendHostContextChange({
viewport: { width: 1024, height: 768 },
containerDimensions: { width: 1024, maxHeight: 768 },
});
await flush();

// getHostContext should have accumulated all updates:
// - locale from initial (unchanged)
// - theme from first partial update
// - viewport from second partial update
// - viewport and containerDimensions from second partial update
const context = newApp.getHostContext();
expect(context?.theme).toBe("dark");
expect(context?.locale).toBe("en-US");
expect(context?.viewport).toEqual({ width: 1024, height: 768 });
expect(context?.viewport).toEqual({
width: 1024,
height: 768,
});
expect(context?.containerDimensions).toEqual({
width: 1024,
maxHeight: 768,
});

await newAppTransport.close();
await newBridgeTransport.close();
Expand Down
3 changes: 2 additions & 1 deletion src/app-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,8 @@ export class AppBridge extends Protocol<
* ```typescript
* bridge.setHostContext({
* theme: "dark",
* viewport: { width: 800, height: 600 }
* viewport: { width: 800, height: 600 },
* containerDimensions: { maxHeight: 600, width: 800 }
* });
* ```
*
Expand Down
Loading
Loading