Fix autoResize reporting viewport height when content is taller (#525)

fit-content clamps to the containing block's available size. For <html>,
that's the iframe viewport, so when content exceeds the viewport height
the SDK reported the viewport height instead of the true content height,
causing internal scrolling instead of iframe growth.

max-content has no available-space constraint and correctly reports the
intrinsic content height in both directions (shrink and grow). Width
stays fit-content to preserve responsive wrapping.
This commit is contained in:
Mel Ludowise 2026-03-06 08:30:13 -05:00 • committed by GitHub
commit 26928b8622
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1119,13 +1119,14 @@ export class App extends Protocol<AppRequest, AppNotification, AppResult> {
scheduled = false;
const html = document.documentElement;
// Measure actual content size by temporarily setting html to fit-content.
// This shrinks html to fit body (including body margins), giving us the
// true minimum size needed by the content.
// Measure actual content size by temporarily overriding html sizing.
// Width uses fit-content so content wraps at the host-provided width.
// Height uses max-content because fit-content would clamp to the viewport
// height when content is taller than the iframe, causing internal scrolling.
const originalWidth = html.style.width;
const originalHeight = html.style.height;
html.style.width = "fit-content";
html.style.height = "fit-content";
html.style.height = "max-content";
const rect = html.getBoundingClientRect();
html.style.width = originalWidth;
html.style.height = originalHeight;