Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(editor): clamp html block layout at the collapse point in the same render its height arrives (#9271)

苗大5b72b8cd4e29
diff --git a/e2e/html-preview-fullscreen.spec.ts b/e2e/html-preview-fullscreen.spec.ts
index 184688999f..0bb8421677 100644
--- a/e2e/html-preview-fullscreen.spec.ts
+++ b/e2e/html-preview-fullscreen.spec.ts
@@ -7,6 +7,13 @@ const html = `<style>html,body{margin:0;padding:0}</style>
${"<!-- long source -->\n".repeat(100)}`;
const content = `${"Paragraph before the preview.\n\n".repeat(60)}\`\`\`html\n${html}\n\`\`\``;
+// Taller than the 480px collapse point, so the block sits collapsed behind
+// "Show all" — enlarging it must not re-expand the inline layout.
+const tallHtml = `<style>html,body{margin:0;padding:0}</style>
+<div style="height:3000px"><input aria-label="Retained input" value="initial"></div>
+${"<!-- long source -->\n".repeat(100)}`;
+const tallContent = `${"Paragraph before the preview.\n\n".repeat(60)}\`\`\`html\n${tallHtml}\n\`\`\``;
+
function readScroll(element: HTMLElement) {
return { top: element.scrollTop, height: element.scrollHeight };
}
@@ -164,6 +171,87 @@ test.describe("HTML preview fullscreen", () => {
});
}
+ // Regression: enlarging a collapsed tall block used to drop the inline clip
+ // and reserve the document's full height in place, so the page re-expanded
+ // for as long as the dialog was open (518px block growing to 3038px and
+ // back) — the same total-height jump the collapse clamp exists to prevent.
+ test("enlarging a collapsed reply block keeps its inline footprint at the clamp", async ({
+ page,
+ }, testInfo) => {
+ const issue = await api.createIssue("Collapsed HTML preview fullscreen");
+ const comment = await api.createComment(issue.id, tallContent);
+ await page.goto(`/${workspaceSlug}/issues/${issue.identifier}`, {
+ waitUntil: "domcontentloaded",
+ });
+ const outer = await scrollContainer(
+ page.getByText("Paragraph before the preview.", { exact: true }).first(),
+ );
+ await outer.evaluate((element) => {
+ element.scrollTop = element.scrollHeight - element.clientHeight;
+ });
+ const block = page.locator(
+ `[data-comment-content="${comment.id}"] [data-dynamic-block="html"]`,
+ );
+ await block.scrollIntoViewIfNeeded();
+ const iframe = block.locator("iframe");
+ await expect(iframe).toBeVisible();
+ // Collapsed, not expanded: the 480px clamp plus the frame chrome.
+ await expect.poll(async () => (await block.boundingBox())?.height).toBe(518);
+ const blockHeight = (await block.boundingBox())!.height;
+ const frameElement = await iframe.elementHandle();
+ const frame = (await frameElement!.contentFrame())!;
+ const input = iframe.contentFrame().getByRole("textbox", { name: "Retained input" });
+ await expect(input).toBeVisible();
+ await input.fill("Keep this document");
+ const timeOrigin = await frame.evaluate(() => performance.timeOrigin);
+ const scroller = await scrollContainer(block);
+ await scroller.evaluate((element) => {
+ element.scrollTop = element.scrollHeight - element.clientHeight;
+ });
+ const before = await scroller.evaluate(readScroll);
+ expect(before.top).toBeGreaterThan(480);
+ const opener = block.getByRole("button", { name: "Fullscreen" });
+ await block.hover();
+ await testInfo.attach("collapsed-inline", {
+ body: await page.screenshot(),
+ contentType: "image/png",
+ });
+ await expect(opener).toBeInViewport();
+
+ await opener.click();
+ const dialog = page.getByRole("dialog");
+ await expect(dialog).toBeVisible();
+ await testInfo.attach("collapsed-enlarged", {
+ body: await page.screenshot(),
+ contentType: "image/png",
+ });
+ expect(
+ await dialog.locator("iframe").evaluate((element, original) => element === original, frameElement),
+ ).toBe(true);
+ expect((await dialog.boundingBox())!.height).toBe(972);
+ // The in-place footprint keeps holding the clamp while enlarged.
+ await expect(block.locator("[data-collapsed]")).toHaveCount(1);
+ expect((await block.boundingBox())!.height).toBe(blockHeight);
+ await expect.poll(async () => scroller.evaluate(readScroll)).toEqual(before);
+ await expect(input).toHaveValue("Keep this document");
+ expect(await frame.evaluate(() => performance.timeOrigin)).toBe(timeOrigin);
+
+ await page.getByRole("button", { name: "Close", exact: true }).click();
+ await expect(page.getByRole("dialog")).toHaveCount(0);
+ await expect(block.locator("[data-collapsed]")).toHaveCount(1);
+ expect((await block.boundingBox())!.height).toBe(blockHeight);
+ await expect.poll(async () => scroller.evaluate(readScroll)).toEqual(before);
+ expect(
+ await iframe.evaluate((element, original) => element === original, frameElement),
+ ).toBe(true);
+ expect(await frame.evaluate(() => performance.timeOrigin)).toBe(timeOrigin);
+ await expect(opener).toBeFocused();
+ await testInfo.attach("collapsed-restored", {
+ body: await page.screenshot(),
+ contentType: "image/png",
+ });
+ });
+
test("reply remeasures content changed while enlarged, including from source", async ({ page }) => {
const interactiveHtml = `<style>html,body{margin:0;padding:0}</style>
<div id="content" style="height:200px">
diff --git a/packages/views/editor/dynamic-block.test.tsx b/packages/views/editor/dynamic-block.test.tsx
index 4753bf764b..f13728b64a 100644
--- a/packages/views/editor/dynamic-block.test.tsx
+++ b/packages/views/editor/dynamic-block.test.tsx
@@ -85,4 +85,59 @@ describe("DynamicBlock", () => {
renderBlock();
expect(screen.queryByRole("button", { name: "Fullscreen" })).toBeNull();
});
+
+ // Regression: a reported bodyHeight must decide the collapse in the same
+ // render it arrives. The clamp used to come from a measure-after-paint
+ // observer, so a tall document painted unclamped for a frame and then
+ // folded back — the height shock virtualized timelines render as flicker.
+ it("decides the collapse from a reported bodyHeight in the same render", () => {
+ const { container } = render(
+ <DynamicBlock
+ kind="html"
+ title="Latency"
+ source="<p>chart</p>"
+ bodyHeight={3000}
+ preview={({ collapsed }) => (
+ <div data-testid="content" style={{ height: collapsed ? 480 : 3000 }}>
+ chart
+ </div>
+ )}
+ />,
+ );
+
+ const body = container.querySelector<HTMLElement>("[data-collapsed]");
+ expect(body).not.toBeNull();
+ expect(body!.style.maxHeight).toBe("480px");
+ // The preview laid out at the clamp, not at the full height.
+ expect(screen.getByTestId("content").style.height).toBe("480px");
+ });
+
+ // Regression: enlarging must not lift the inline clamp. The enlarged dialog
+ // is fixed-position and fills itself, but the in-place footprint has to keep
+ // holding the clamp — dropping the clip for the enlargement re-expanded the
+ // timeline for as long as the dialog was open, the same height shock this
+ // frame exists to prevent.
+ it("keeps the inline clamp while fullscreen", () => {
+ const { container } = render(
+ <DynamicBlock
+ kind="html"
+ title="Latency"
+ source="<p>chart</p>"
+ fullscreen
+ bodyHeight={3000}
+ preview={({ collapsed }) => (
+ <div data-testid="content" style={{ height: collapsed ? 480 : 3000 }}>
+ chart
+ </div>
+ )}
+ />,
+ );
+
+ const body = container.querySelector<HTMLElement>("[data-collapsed]");
+ expect(body).not.toBeNull();
+ expect(body!.style.maxHeight).toBe("480px");
+ // The in-place footprint stays at the clamp, never at the full height.
+ expect(screen.getByTestId("content").style.height).toBe("480px");
+ expect(screen.getByRole("button", { name: "Show all" })).toBeTruthy();
+ });
});
diff --git a/packages/views/editor/dynamic-block.tsx b/packages/views/editor/dynamic-block.tsx
index 3364230cf2..57599c983d 100644
--- a/packages/views/editor/dynamic-block.tsx
+++ b/packages/views/editor/dynamic-block.tsx
@@ -97,8 +97,21 @@ interface DynamicBlockProps {
/**
* The rendered content. It stays mounted while the source view is showing,
* so switching back is instant; `active` says whether it is on screen.
+ * `collapsed` says the frame is clipping the body at the collapse point, so
+ * the preview must lay out at the clamp, never at its full height — a tall
+ * document that paints unclamped for even a frame slams virtualized
+ * timelines with a total-height shock (visible flicker on scroll jumps).
*/
- preview: (options: { active: boolean }) => ReactNode;
+ preview: (options: { active: boolean; collapsed: boolean }) => ReactNode;
+ /**
+ * The preview body's content height in px, when the preview knows it (the
+ * html block's measured document height). Passing it moves the collapse
+ * decision out of DOM measurement: the frame flips to collapsed in the same
+ * render the height arrives, so the clamp and the height cannot land a
+ * frame apart. Omit — or pass null while the height is still unknown —
+ * for previews the frame must measure (mermaid).
+ */
+ bodyHeight?: number | null;
className?: string;
}
@@ -112,11 +125,41 @@ export function DynamicBlock({
fullscreen = false,
fullscreenButtonRef,
preview,
+ bodyHeight,
className,
}: DynamicBlockProps) {
const { t } = useT("editor");
const [view, setView] = useState<DynamicBlockView>("preview");
const [copied, setCopied] = useState(false);
+ const [expanded, setExpanded] = useState(false);
+ // Overflow state for previews the frame must measure itself (mermaid). A
+ // preview that reports its height makes this read obsolete — the collapse
+ // decision then lands in the same render the height arrives, so the clamp
+ // and the height can never paint a frame apart.
+ const measuredBodyRef = useRef<HTMLDivElement>(null);
+ const [measuredOverflowing, setMeasuredOverflowing] = useState(false);
+ useLayoutEffect(() => {
+ if (bodyHeight != null) return;
+ const el = measuredBodyRef.current;
+ if (!el) return;
+ const measure = () =>
+ setMeasuredOverflowing(el.offsetHeight > DYNAMIC_BLOCK_COLLAPSE_AT_PX);
+ measure();
+ if (typeof ResizeObserver === "undefined") return;
+ const observer = new ResizeObserver(measure);
+ observer.observe(el);
+ return () => observer.disconnect();
+ }, [bodyHeight]);
+ const overflowing =
+ bodyHeight != null
+ ? bodyHeight > DYNAMIC_BLOCK_COLLAPSE_AT_PX
+ : measuredOverflowing;
+ // The clamp is an inline-layout concern and stays on while the surface is
+ // enlarged: the dialog is fixed-position, so it escapes the clip and fills
+ // its own box, while the in-place footprint keeps holding the clamp —
+ // dropping the clip for the enlargement would re-expand the timeline for as
+ // long as the dialog is open, the very height jump this frame prevents.
+ const collapsed = overflowing && !expanded;
const Icon = KIND_ICON[kind];
const kindLabel = KIND_LABEL[kind];
const trimmedTitle = title?.trim();
@@ -236,29 +279,86 @@ export function DynamicBlock({
/>
)}
<div hidden={!!error && !fullscreen}>
- <CollapsibleBody>{preview({ active: view === "preview" && !error })}</CollapsibleBody>
+ <CollapsibleBody
+ collapsed={collapsed}
+ onExpand={() => setExpanded(true)}
+ measureRef={bodyHeight == null ? measuredBodyRef : undefined}
+ >
+ {preview({ active: view === "preview" && !error, collapsed })}
+ </CollapsibleBody>
</div>
</TabsContent>
<TabsContent value="source">
- <CollapsibleBody>
+ <SelfCollapsingBody>
<CodeBlockStatic
language={SOURCE_LANGUAGE[kind]}
body={source}
className="!m-0 !rounded-none !bg-muted"
/>
- </CollapsibleBody>
+ </SelfCollapsingBody>
</TabsContent>
</Tabs>
);
}
/**
- * Takes its content's height, collapsed past DYNAMIC_BLOCK_COLLAPSE_AT_PX
- * with a fade and "Show all". The content keeps laying out at full height
- * underneath, so expanding only lifts the clip — an HTML preview or diagram
- * is not rebuilt.
+ * Clips the preview body past DYNAMIC_BLOCK_COLLAPSE_AT_PX with a fade and
+ * "Show all". Whether to clip is decided by the frame (`collapsed`): either
+ * from a preview-reported height in the same render the height arrives, or —
+ * for previews the frame measures — from the ResizeObserver below. The content
+ * keeps laying out at full height underneath the clip (the preview clamps
+ * its own layout height when `collapsed`), so expanding only lifts the clip
+ * — an HTML preview or diagram is not rebuilt.
+ */
+function CollapsibleBody({
+ collapsed,
+ onExpand,
+ measureRef,
+ children,
+}: {
+ collapsed: boolean;
+ onExpand: () => void;
+ /** Overflow measurement target for previews the frame must measure itself. */
+ measureRef?: Ref<HTMLDivElement>;
+ children: ReactNode;
+}) {
+ const { t } = useT("editor");
+
+ return (
+ <div
+ className="relative overflow-hidden"
+ data-collapsed={collapsed ? "" : undefined}
+ style={collapsed ? { maxHeight: DYNAMIC_BLOCK_COLLAPSE_AT_PX } : undefined}
+ >
+ <div ref={measureRef}>{children}</div>
+ {collapsed && (
+ <>
+ <div className="pointer-events-none absolute inset-x-0 bottom-0 h-24 bg-gradient-to-b from-transparent to-surface" />
+ <Button
+ type="button"
+ variant="outline"
+ size="sm"
+ className="absolute bottom-3 left-1/2 -translate-x-1/2 rounded-full bg-surface shadow-[var(--surface-shadow)]"
+ onClick={onExpand}
+ >
+ <ChevronDown />
+ {t(($) => $.dynamic_block.show_all)}
+ </Button>
+ </>
+ )}
+ </div>
+ );
+}
+
+/**
+ * The source view's body keeps its own measuring collapse (the behavior the
+ * preview's body had before the reported-height clamp): the frame cannot know
+ * a code block's height, and folding long sources stays useful there. Only
+ * the preview moved to the frame-decided clamp — its height is known, and the
+ * measure-after-paint race on that path is what the html-block flicker fix
+ * removes.
*/
-function CollapsibleBody({ children }: { children: ReactNode }) {
+function SelfCollapsingBody({ children }: { children: ReactNode }) {
const { t } = useT("editor");
const contentRef = useRef<HTMLDivElement>(null);
const [contentHeight, setContentHeight] = useState(0);
diff --git a/packages/views/editor/html-block-preview.test.tsx b/packages/views/editor/html-block-preview.test.tsx
index 428bb00b33..c68bdcc1ee 100644
--- a/packages/views/editor/html-block-preview.test.tsx
+++ b/packages/views/editor/html-block-preview.test.tsx
@@ -147,6 +147,62 @@ describe("HtmlBlockPreview — height", () => {
render(<HtmlBlockPreview html="<p>chart</p>" />);
expect(body(inlineFrame()).style.height).toBe("300px");
});
+
+ // Regression: the reported height used to land a frame before the frame's
+ // collapse clip did, so a tall document painted unclipped and then folded
+ // back — a total-height shock wave virtualized timelines render as flicker
+ // when a scroll jump lands on the block. The clip must apply in the same
+ // render the height arrives.
+ it("clips a tall document in the same render its height arrives", () => {
+ render(<HtmlBlockPreview html="<p>tall</p>" />);
+ const frame = inlineFrame();
+
+ post(frame, { type: "height", height: 3000 });
+ // The body keeps the document's full height; the frame's clip decides the
+ // visible box right away.
+ expect(body(frame).style.height).toBe("3000px");
+ const clip = frame.closest<HTMLElement>("[data-collapsed]");
+ expect(clip).not.toBeNull();
+ expect(clip!.style.maxHeight).toBe("480px");
+ expect(screen.getByRole("button", { name: "Show all" })).toBeTruthy();
+
+ fireEvent.click(screen.getByRole("button", { name: "Show all" }));
+ expect(frame.closest("[data-collapsed]")).toBeNull();
+ expect(screen.queryByRole("button", { name: "Show all" })).toBeNull();
+ });
+
+ it("starts a tall cached document clipped too, not unclipped", () => {
+ const first = render(<HtmlBlockPreview html="<p>tall</p>" />);
+ post(inlineFrame(), { type: "height", height: 3000 });
+ first.unmount();
+
+ render(<HtmlBlockPreview html="<p>tall</p>" />);
+ const clip = inlineFrame().closest<HTMLElement>("[data-collapsed]");
+ expect(clip).not.toBeNull();
+ expect(clip!.style.maxHeight).toBe("480px");
+ });
+
+ // Regression: re-authoring a block must restart measurement. The body used
+ // to keep its measurement state across a content change, so a stale
+ // `frozen` runaway guard ignored every report from the new document
+ // forever, and stale `loaded`/`timedOut` could reveal it unmeasured.
+ it("measures re-authored content again, starting clean", () => {
+ const view = render(<HtmlBlockPreview html="<p>first</p>" />);
+ const frame = inlineFrame();
+ // Three equal steps trip the runaway guard, which pins the height and
+ // ignores every further report — here at 400 forever.
+ post(frame, { type: "height", height: 200 });
+ post(frame, { type: "height", height: 300 });
+ post(frame, { type: "height", height: 400 });
+ post(frame, { type: "height", height: 500 });
+ expect(body(frame).style.height).toBe("400px");
+
+ view.rerender(<HtmlBlockPreview html="<p>second</p>" />);
+ const next = inlineFrame();
+ expect(next).not.toBe(frame);
+ post(next, { type: "height", height: 250 });
+ expect(body(next).style.height).toBe("250px");
+ });
});
describe("HtmlBlockPreview — errors", () => {
@@ -203,6 +259,31 @@ describe("HtmlBlockPreview — reload", () => {
expect(within(block).queryByText("Rendering...")).toBeNull();
});
+ // Regression: the height handed up to the frame decides the inline collapse,
+ // so it must be re-reported after a reload — otherwise the collapse decision
+ // would keep describing the document that was replaced.
+ it("tracks the reloaded document with the collapse decision", () => {
+ render(<HtmlBlockPreview html="<p>tall</p>" />);
+ const clip = () => inlineFrame().closest<HTMLElement>("[data-collapsed]");
+
+ post(inlineFrame(), { type: "height", height: 3000 });
+ expect(clip()).not.toBeNull();
+
+ fireEvent.click(screen.getByRole("button", { name: "Reload" }));
+ // Unknown until the fresh document reports: the session cache holds the
+ // collapse in place so the reload itself moves nothing.
+ expect(clip()).not.toBeNull();
+ post(inlineFrame(), { type: "height", height: 200 });
+ expect(clip()).toBeNull();
+ expect(screen.queryByRole("button", { name: "Show all" })).toBeNull();
+
+ fireEvent.click(screen.getByRole("button", { name: "Reload" }));
+ expect(clip()).toBeNull();
+ post(inlineFrame(), { type: "height", height: 3000 });
+ expect(clip()).not.toBeNull();
+ expect(clip()!.style.maxHeight).toBe("480px");
+ });
+
it("waits for the reloaded document before restarting the missing-bridge timeout", () => {
vi.useFakeTimers();
try {
@@ -303,4 +384,36 @@ describe("HtmlBlockPreview — fullscreen", () => {
expect(source.closest("[data-collapsed]")).toBeNull();
expect(screen.queryByRole("button", { name: "Show all" })).toBeNull();
});
+
+ // Regression: enlarging a collapsed tall block used to reserve the full
+ // document height inline (and lift the clip), re-expanding the timeline for
+ // as long as the dialog was open — the same total-height jump the reported
+ // height exists to prevent. The in-place footprint must stay at the clamp;
+ // the dialog fills its own box.
+ it("reserves the collapsed inline height while enlarged", () => {
+ render(<HtmlBlockPreview html="<p>tall</p>" />);
+ const frame = inlineFrame();
+ post(frame, { type: "height", height: 3000 });
+ const clip = frame.closest<HTMLElement>("[data-collapsed]");
+ expect(clip).not.toBeNull();
+
+ fireEvent.click(screen.getByRole("button", { name: "Fullscreen" }));
+
+ const dialog = screen.getByRole("dialog");
+ const reserved = dialog.parentElement as HTMLElement;
+ expect(reserved.style.height).toBe("480px");
+ expect(frame.closest("[data-collapsed]")).toBe(clip);
+ expect(clip!.style.maxHeight).toBe("480px");
+ // The enlarged surface fills its own box; closing restores the inline
+ // layout, which keeps the document's full height under the clip.
+ expect(frame.parentElement?.style.height).toBe("100%");
+ expect(dialog.querySelector("iframe")).toBe(frame);
+
+ fireEvent.click(screen.getByRole("button", { name: "Close" }));
+
+ expect(screen.queryByRole("dialog")).toBeNull();
+ expect((dialog.parentElement as HTMLElement).style.height).toBe("");
+ expect(frame.closest("[data-collapsed]")).toBe(clip);
+ expect(frame.parentElement?.style.height).toBe("3000px");
+ });
});
diff --git a/packages/views/editor/html-block-preview.tsx b/packages/views/editor/html-block-preview.tsx
index 6990f0daac..d34a3a102a 100644
--- a/packages/views/editor/html-block-preview.tsx
+++ b/packages/views/editor/html-block-preview.tsx
@@ -9,6 +9,17 @@
* charts floating in blank space. An uncaught script error replaces the
* preview with an explanation; fullscreen still shows whatever did render.
*
+ * The laid-out height is also handed up to the frame (`onBodyHeightChange`),
+ * so the collapse clip decision lands in the same paint the height arrives: a
+ * tall document is clipped at the collapse point immediately instead of
+ * painting unclamped for a frame and then folding back — that total-height
+ * shock wave is what virtualized timelines render as flicker when a scroll
+ * jump lands on the block. The enlarged surface draws no extra height either:
+ * while the dialog is open the in-place footprint stays at the collapse clamp
+ * (the dialog is fixed-position, so it fills itself regardless of the inline
+ * clip), and the bridge re-reports after close so the collapse decision
+ * tracks the document that is actually shown.
+ *
* Reached through RichFenceBlock (rich-content/rich-code-block.tsx) for closed
* fences only. NOT used in the editable Tiptap NodeView — that path must keep
* `<NodeViewContent as="code" />` so the user can continue typing.
@@ -106,6 +117,10 @@ export function HtmlBlockPreview({ html, title }: HtmlBlockPreviewProps) {
const [error, setError] = useState<DynamicBlockError | null>(null);
const [fullscreen, setFullscreen] = useState(false);
const [reloadKey, setReloadKey] = useState(0);
+ // The body's laid-out height, reported by HtmlBlockBody below. The frame
+ // turns it into the collapse decision in the same paint the height lands
+ // (see the flicker note in the file header).
+ const [bodyHeight, setBodyHeight] = useState<number | null>(null);
const frameTitle = t(($) => $.code_block.html_preview);
const reload = () => {
@@ -133,7 +148,11 @@ export function HtmlBlockPreview({ html, title }: HtmlBlockPreviewProps) {
fullscreen={fullscreen}
onFullscreen={() => setFullscreen(true)}
onReload={reload}
- preview={({ active }) => (
+ bodyHeight={bodyHeight}
+ preview={({ active, collapsed }) => (
+ // Keyed by the content: a re-authored block restarts measurement
+ // from scratch — a stale `frozen`/`loaded` from the previous
+ // document must never pin or reveal the new one.
<HtmlBlockBody
key={html}
html={html}
@@ -141,9 +160,11 @@ export function HtmlBlockPreview({ html, title }: HtmlBlockPreviewProps) {
title={frameTitle}
active={active}
fullscreen={fullscreen}
+ collapsed={collapsed}
reloadKey={reloadKey}
onReload={reload}
onFullscreenChange={setFullscreen}
+ onBodyHeightChange={setBodyHeight}
onError={setError}
/>
)}
@@ -158,9 +179,11 @@ function HtmlBlockBody({
title,
active,
fullscreen,
+ collapsed,
reloadKey,
onReload,
onFullscreenChange,
+ onBodyHeightChange,
onError,
}: {
html: string;
@@ -168,9 +191,12 @@ function HtmlBlockBody({
title: string;
active: boolean;
fullscreen: boolean;
+ /** The frame is clipping the inline body at the collapse point. */
+ collapsed: boolean;
reloadKey: number;
onReload: () => void;
onFullscreenChange: (open: boolean) => void;
+ onBodyHeightChange: (height: number) => void;
onError: (error: DynamicBlockError) => void;
}) {
const iframeRef = useRef<HTMLIFrameElement>(null);
@@ -242,10 +268,29 @@ function HtmlBlockBody({
height ?? (timedOut ? UNMEASURED_HEIGHT_PX : (cachedHeight ?? DYNAMIC_BLOCK_MIN_BODY_PX)),
);
+ // Hand the laid-out height up to the frame so its collapse clip applies in
+ // the same paint the height lands — a layout effect keeps any intermediate
+ // (unclipped) frame from painting. See the flicker note in the file header.
+ const onBodyHeightChangeRef = useRef(onBodyHeightChange);
+ useLayoutEffect(() => {
+ onBodyHeightChangeRef.current = onBodyHeightChange;
+ });
+ useLayoutEffect(() => {
+ onBodyHeightChangeRef.current(bodyHeight);
+ }, [bodyHeight]);
+
return (
<HtmlPreviewSurface
open={fullscreen}
- inlineHeight={active ? bodyHeight : 0}
+ // While enlarged, the wrapper holds the block's in-place footprint. A
+ // collapsed body keeps showing its clamp there — reserving the full
+ // document height would re-expand the timeline for as long as the
+ // dialog is open, the same total-height jump this file exists to
+ // prevent. The dialog itself is fixed-position: it fills its own box
+ // and is untouched by the inline clip.
+ inlineHeight={
+ active ? (collapsed ? Math.min(bodyHeight, DYNAMIC_BLOCK_COLLAPSE_AT_PX) : bodyHeight) : 0
+ }
onOpenChange={onFullscreenChange}
onReload={onReload}
title={title}