diff --git a/src/app/features/widgets/WidgetIframe.tsx b/src/app/features/widgets/WidgetIframe.tsx index 960c34a2..e184fcaf 100644 --- a/src/app/features/widgets/WidgetIframe.tsx +++ b/src/app/features/widgets/WidgetIframe.tsx @@ -38,7 +38,8 @@ export function WidgetIframe({ widget, roomId, mx, onCapabilityRequest }: Widget userId, displayName, avatarUrl, - widget.id + widget.id, + mx ); useEffect(() => { @@ -60,6 +61,11 @@ export function WidgetIframe({ widget, roomId, mx, onCapabilityRequest }: Widget messaging.once('ready', () => setReady(true)); + // Set iframe src after ClientWidgetApi is listening for the load event. + // This avoids a race condition where the iframe loads before the widget + // API transport is ready to perform the capability handshake. + iframe.src = resolvedUrl; + messaging.on('action:org.matrix.msc2876.read_events', (ev: CustomEvent) => { const room = mx.getRoom(roomId); const events: Partial[] = []; @@ -135,7 +141,6 @@ export function WidgetIframe({ widget, roomId, mx, onCapabilityRequest }: Widget