From 5c4f1e744cf494eccaf7e9ba51fbe7d7ca47be55 Mon Sep 17 00:00:00 2001
From: Brooklyn Nicholson
Date: Mon, 17 Aug 2026 12:34:22 -0500
Subject: [PATCH] fix(desktop): inline preview frames size to their content
instead of a fixed default
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The frame was a hardcoded 280px unless the model guessed a height attribute
— tall pages clipped (the flip-clock demo cut its last digit), short ones
floated in dead space. The opaque-origin sandbox means the parent can't
measure the document, but we own the srcdoc string: a tiny injected script
observes the document with ResizeObserver and posts its scrollHeight up via
postMessage, and the frame tracks it live within the 120-1200 clamp.
Reports are validated before they can move layout — per-mount random token
(two previews in one transcript, or a hostile page inventing messages,
can't move each other's frames), finite-number check, clamp. A 4px
tolerance stops vh-sized pages (which measure exactly what they're given)
from oscillating; an explicit height attribute still opts out of
auto-sizing entirely.
---
.../inline-preview-directive.test.ts | 58 ++++++++-
.../assistant-ui/inline-preview-directive.tsx | 122 ++++++++++++++++--
2 files changed, 164 insertions(+), 16 deletions(-)
diff --git a/apps/desktop/src/components/assistant-ui/inline-preview-directive.test.ts b/apps/desktop/src/components/assistant-ui/inline-preview-directive.test.ts
index 9f65458688..10f2051134 100644
--- a/apps/desktop/src/components/assistant-ui/inline-preview-directive.test.ts
+++ b/apps/desktop/src/components/assistant-ui/inline-preview-directive.test.ts
@@ -1,18 +1,62 @@
import { describe, expect, it } from 'vitest'
-import { directiveFrameHeight } from './inline-preview-directive'
+import { directiveFrameHeight, frameHeightFromMessage, withMeasurement } from './inline-preview-directive'
describe('directiveFrameHeight', () => {
- it('defaults when absent or garbage', () => {
- expect(directiveFrameHeight(undefined)).toBe(280)
- expect(directiveFrameHeight('')).toBe(280)
- expect(directiveFrameHeight('tall')).toBe(280)
- expect(directiveFrameHeight('12.5')).toBe(280)
+ it('returns null (auto-size) when absent or garbage', () => {
+ expect(directiveFrameHeight(undefined)).toBeNull()
+ expect(directiveFrameHeight('')).toBeNull()
+ expect(directiveFrameHeight('tall')).toBeNull()
+ expect(directiveFrameHeight('12.5')).toBeNull()
})
- it('clamps to the sane band', () => {
+ it('clamps an explicit height to the sane band', () => {
expect(directiveFrameHeight('50')).toBe(120)
expect(directiveFrameHeight('480')).toBe(480)
expect(directiveFrameHeight('99999')).toBe(1200)
})
})
+
+describe('withMeasurement', () => {
+ it('injects the measuring script before
hi