Skip to content

The agent that grows with you

fix(desktop): remount social embeds per descriptor and share the default height

kshitijk4poorf9f132915fea
diff --git a/apps/desktop/src/components/assistant-ui/embeds/embed-consent.tsx b/apps/desktop/src/components/assistant-ui/embeds/embed-consent.tsx
index c2fa1bff21a..88e24e90744 100644
--- a/apps/desktop/src/components/assistant-ui/embeds/embed-consent.tsx
+++ b/apps/desktop/src/components/assistant-ui/embeds/embed-consent.tsx
@@ -6,6 +6,7 @@ import { SplitButton } from '@/components/ui/split-button'
import { Play } from '@/lib/icons'
import { allowProvider } from '@/store/embed-consent'
+import { EMBED_DEFAULT_H } from './embed-size'
import type { EmbedDescriptor } from './providers/types'
// Privacy placeholder shown before an embed reaches out to a third party. Sized
@@ -17,7 +18,7 @@ export function EmbedFacade({ descriptor, onLoad }: { descriptor: EmbedDescripto
const style: CSSProperties = descriptor.aspectRatio
? { aspectRatio: descriptor.aspectRatio }
- : { height: descriptor.height ?? 320 }
+ : { height: descriptor.height ?? EMBED_DEFAULT_H }
const actions = [
{ id: 'once', label: `Load ${descriptor.label}` },
diff --git a/apps/desktop/src/components/assistant-ui/embeds/embed-size.ts b/apps/desktop/src/components/assistant-ui/embeds/embed-size.ts
index 3f3da9fb30f..5208e64c8fa 100644
--- a/apps/desktop/src/components/assistant-ui/embeds/embed-size.ts
+++ b/apps/desktop/src/components/assistant-ui/embeds/embed-size.ts
@@ -2,3 +2,7 @@
// UrlEmbed so height follows the aspect ratio; fenced renderers (mermaid, svg)
// reuse it directly. Pure CSS — no measuring.
export const EMBED_MAX_H = '33dvh'
+
+// Fallback height (px) for non-ratio embeds that don't declare one: the consent
+// placeholder, the intrinsic-size hint, and social frames until they measure.
+export const EMBED_DEFAULT_H = 320
diff --git a/apps/desktop/src/components/assistant-ui/embeds/social-embed.tsx b/apps/desktop/src/components/assistant-ui/embeds/social-embed.tsx
index 1813305abfa..0acbb4bdb32 100644
--- a/apps/desktop/src/components/assistant-ui/embeds/social-embed.tsx
+++ b/apps/desktop/src/components/assistant-ui/embeds/social-embed.tsx
@@ -2,7 +2,8 @@
import { useEffect, useMemo, useRef, useState } from 'react'
-import type { EmbedDescriptor } from './providers/types'
+import { EMBED_DEFAULT_H } from './embed-size'
+import type { EmbedDescriptor, EmbedProvider } from './providers/types'
import { useIsDark } from './use-is-dark'
// X and Instagram render in the provider's own cross-origin iframe, like every
@@ -14,17 +15,14 @@ import { useIsDark } from './use-is-dark'
// window-open policy denies them anyway), forms and modals. The frame is
// cross-origin, so allow-same-origin gives it nothing of ours, and Electron
// injects no preload into subframes.
-export const SOCIAL_FRAME_SANDBOX = 'allow-scripts allow-same-origin'
+const SOCIAL_FRAME_SANDBOX = 'allow-scripts allow-same-origin'
-const FRAME_ORIGIN: Record<string, string> = {
+const FRAME_ORIGIN: Partial<Record<EmbedProvider, string>> = {
instagram: 'https://www.instagram.com',
twitter: 'https://platform.twitter.com'
}
-// Placeholder until the embed page reports its rendered height.
-const DEFAULT_HEIGHT = 320
-
-export function socialFrameSrc(descriptor: EmbedDescriptor, theme: 'dark' | 'light'): string {
+function socialFrameSrc(descriptor: EmbedDescriptor, theme: 'dark' | 'light'): string {
if (descriptor.renderer !== 'tweet') {
return descriptor.embedUrl
}
@@ -48,7 +46,7 @@ interface EmbedMessage {
// own widget scripts listen for: X sends {"twttr.embed": {method:
// "twttr.private.resize", params: [{height}]}}, Instagram the JSON string
// {"type": "MEASURE", "details": {height}}. Only that number is read.
-export function reportedHeight(data: unknown): number | null {
+function reportedHeight(data: unknown): number | null {
let message = data
if (typeof message === 'string') {
@@ -78,7 +76,7 @@ export function reportedHeight(data: unknown): number | null {
export default function SocialEmbedRenderer({ descriptor }: { descriptor: EmbedDescriptor }) {
const isDark = useIsDark()
const ref = useRef<HTMLIFrameElement | null>(null)
- const [height, setHeight] = useState(descriptor.height ?? DEFAULT_HEIGHT)
+ const [height, setHeight] = useState(descriptor.height ?? EMBED_DEFAULT_H)
const src = useMemo(() => socialFrameSrc(descriptor, isDark ? 'dark' : 'light'), [descriptor, isDark])
useEffect(() => {
diff --git a/apps/desktop/src/components/assistant-ui/embeds/url-embed.tsx b/apps/desktop/src/components/assistant-ui/embeds/url-embed.tsx
index 35996b0aa37..2ee29d145bf 100644
--- a/apps/desktop/src/components/assistant-ui/embeds/url-embed.tsx
+++ b/apps/desktop/src/components/assistant-ui/embeds/url-embed.tsx
@@ -7,7 +7,7 @@ import { PrettyLink } from '@/lib/external-link'
import { $embedAllowed, $embedMode } from '@/store/embed-consent'
import { EmbedFacade } from './embed-consent'
-import { EMBED_MAX_H } from './embed-size'
+import { EMBED_DEFAULT_H, EMBED_MAX_H } from './embed-size'
import { EmbedFail } from './fail'
import type { EmbedDescriptor } from './providers/types'
import { RichBoundary } from './rich-boundary'
@@ -22,7 +22,7 @@ function intrinsicHeight(descriptor: EmbedDescriptor): number {
return Math.round((descriptor.maxWidth ?? 640) / descriptor.aspectRatio)
}
- return descriptor.height ?? 320
+ return descriptor.height ?? EMBED_DEFAULT_H
}
function LazyRenderer({ descriptor }: { descriptor: EmbedDescriptor }) {
@@ -30,7 +30,7 @@ function LazyRenderer({ descriptor }: { descriptor: EmbedDescriptor }) {
// page's height messages. The tweet check also narrows the union to
// FrameEmbed for the iframe renderers below.
if (descriptor.renderer === 'tweet' || descriptor.provider === 'instagram') {
- return <SocialEmbedRenderer descriptor={descriptor} />
+ return <SocialEmbedRenderer descriptor={descriptor} key={descriptor.id} />
}
if (descriptor.provider === 'youtube') {