You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -88,6 +88,7 @@ It accepts the following props:
88
88
-**`htmlProps`**: Optional props for the internal `<HTMLResourceRenderer>`
89
89
-**`style`**: Optional custom styles for the iframe
90
90
-**`iframeProps`**: Optional props passed to the iframe element
91
+
-**`iframeRenderData`**: Optional `Record<string, unknown>` to pass data to the iframe upon rendering. This enables advanced use cases where the parent application needs to provide initial state or configuration to the sandboxed iframe content.
91
92
-**`remoteDomProps`**: Optional props for the internal `<RemoteDOMResourceRenderer>`
92
93
-**`library`**: Optional component library for Remote DOM resources (defaults to `basicComponentLibrary`)
93
94
-**`remoteElements`**: remote element definitions for Remote DOM resources.
-**`proxy`**: Optional. A URL to a static "proxy" script for rendering external URLs. See [Using a Proxy for External URLs](./using-a-proxy.md) for details.
51
51
-**`iframeProps`**: Optional props passed to iframe elements (for HTML/URL resources)
52
52
-**`ref`**: Optional React ref to access the underlying iframe element
53
+
-**`iframeRenderData`**: Optional `Record<string, unknown>` to pass data to the iframe upon rendering. This enables advanced use cases where the parent application needs to provide initial state or configuration to the sandboxed iframe content.
53
54
-**`remoteDomProps`**: Optional props for the `<RemoteDOMResourceRenderer>`
54
55
-**`library`**: Optional component library for Remote DOM resources (defaults to `basicComponentLibrary`)
55
56
-**`remoteElements`**: Optional remote element definitions for Remote DOM resources. REQUIRED for Remote DOM snippets.
@@ -138,6 +139,63 @@ function App({ mcpResource }) {
138
139
/>
139
140
```
140
141
142
+
### Passing Render-Time Data to Iframes
143
+
144
+
The `iframeRenderData` prop allows you to send a data payload to an iframe as it renders. This is useful for initializing the iframe with dynamic data from the parent application.
145
+
146
+
When `iframeRenderData` is provided:
147
+
1. The iframe's URL will automatically include `?waitForRenderData=true`. The iframe's internal script can use this to know it should wait for data instead of immediately rendering.
148
+
2. The data is sent to the iframe via `postMessage` using a dual-mechanism approach to ensure reliable delivery:
149
+
-**On Load**: A `ui-lifecycle-iframe-render-data` message is sent as soon as the iframe's `onLoad` event fires.
150
+
-**On Ready**: If the iframe sends a `ui-lifecycle-iframe-ready` message, the parent will respond with the same `ui-lifecycle-iframe-render-data` payload.
151
+
152
+
This ensures the data is delivered whether the iframe is ready immediately or needs to perform setup work first.
153
+
154
+
```tsx
155
+
<UIResourceRenderer
156
+
resource={mcpResource.resource}
157
+
htmlProps={{
158
+
iframeRenderData: {
159
+
theme: 'dark',
160
+
user: { id: '123', name: 'John Doe' }
161
+
}
162
+
}}
163
+
onUIAction={handleUIAction}
164
+
/>
165
+
```
166
+
167
+
Inside the iframe, you can listen for this data:
168
+
169
+
```javascript
170
+
// In the iframe's script
171
+
172
+
// If the iframe needs to do async work, it can tell the parent when it's ready
0 commit comments