The best way to control Claude Code, Codex and more from any computer or phone
fix(web): full-screen HTML pages fit their content and zoom by reflowing (#22349)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Zeus-Deus committed
Nov 11, 2026 at 10:01 UTC
5bb5d533122dcc0434b630ccb8d53c9c3682286c
3 files changed
+112
-13
apps/web/src/components/chat/HtmlRenderDialog.browser.test.tsx
new
+74
@@ -0,0 +1,74 @@
1
+import { HTML_RENDER_DEFAULT_FONTS, htmlRenderTheme } from "@t3tools/shared/htmlRender";
2
+import { T3_CODE_DARK_THEME_COLORS } from "@t3tools/shared/themePalettes";
3
+import { expect, it, vi } from "vite-plus/test";
4
+import { page, userEvent } from "vite-plus/test/browser";
5
+
6
+import "~/index.css";
7
+import { act, render } from "../../../test/render";
8
+
9
+vi.mock(import("~/hooks/useHtmlRenderTheme"), async (original) => ({
10
+ ...(await original()),
11
+ useHtmlRenderTheme: () =>
12
+ htmlRenderTheme(T3_CODE_DARK_THEME_COLORS, "dark", HTML_RENDER_DEFAULT_FONTS),
13
+}));
14
+
15
+import { HtmlRenderDialog } from "./HtmlRenderDialog";
16
+
17
+const dialog = (
18
+ <HtmlRenderDialog
19
+ src="https://environment.test/page.html"
20
+ htmlRender={{ attachmentId: "html", title: "Diagram", height: 400 }}
21
+ onClose={() => {}}
22
+ />
23
+);
24
+
25
+function frameAndCard() {
26
+ const frame = document.querySelector<HTMLIFrameElement>('[role="dialog"] iframe')!;
27
+ let card = frame.parentElement!;
28
+ while (getComputedStyle(card).overflowY !== "auto") card = card.parentElement!;
29
+ return { frame, card };
30
+}
31
+
32
+async function reportHeight(frame: HTMLIFrameElement, height: number) {
33
+ await act(() => {
34
+ window.dispatchEvent(
35
+ new MessageEvent("message", {
36
+ source: frame.contentWindow,
37
+ data: { jsonrpc: "2.0", method: "ui/notifications/size-changed", params: { height } },
38
+ }),
39
+ );
40
+ });
41
+}
42
+
43
+it("fits the frame to the page's height and scrolls only the card", async () => {
44
+ await page.viewport(1280, 800);
45
+ await using _screen = await render(dialog);
46
+ const { frame, card } = frameAndCard();
47
+ await reportHeight(frame, 300);
48
+ expect(frame.getBoundingClientRect().height).toBe(300);
49
+ expect(card.scrollHeight).toBe(card.clientHeight);
50
+ await reportHeight(frame, 5000);
51
+ expect(frame.getBoundingClientRect().height).toBe(5000);
52
+ expect(card.clientHeight).toBeLessThan(800);
53
+ expect(card.scrollHeight).toBeGreaterThan(card.clientHeight);
54
+});
55
+
56
+it("zooms by reflowing the page to the card's width instead of overflowing it", async () => {
57
+ await page.viewport(1280, 800);
58
+ await using _screen = await render(dialog);
59
+ const { frame, card } = frameAndCard();
60
+ await reportHeight(frame, 300);
61
+ const contentWidth = frame.getBoundingClientRect().width;
62
+ for (let step = 0; step < 4; step += 1) {
63
+ await userEvent.click(page.getByRole("button", { name: "Zoom in" }));
64
+ }
65
+ expect(frame.getBoundingClientRect().width).toBeCloseTo(contentWidth, 0);
66
+ expect(frame.getBoundingClientRect().height).toBe(600);
67
+ expect(card.scrollWidth).toBe(card.clientWidth);
68
+ await userEvent.click(page.getByRole("button", { name: "Reset zoom" }));
69
+ for (let step = 0; step < 2; step += 1) {
70
+ await userEvent.click(page.getByRole("button", { name: "Zoom out" }));
71
+ }
72
+ expect(frame.getBoundingClientRect().width).toBeCloseTo(contentWidth, 0);
73
+ expect(frame.getBoundingClientRect().height).toBe(150);
74
+});
apps/web/src/components/chat/HtmlRenderDialog.tsx
+37
-12
@@ -1,19 +1,40 @@
1
import type { ScopedThreadRef } from "@t3tools/contracts";
2
+import {
3
+ HTML_RENDER_COLUMN_WIDTH,
4
+ htmlRenderFrameHeight,
5
+ type HtmlRenderReference,
6
+} from "@t3tools/shared/htmlRender";
7
import { MinusIcon, PlusIcon, XIcon } from "lucide-react";
8
import { useRef, useState } from "react";
9
10
+import { observeResize } from "~/lib/observeResize";
11
+
12
import { HtmlRenderDocument } from "../files/BrowserDocumentFrame";
13
import { Button } from "../ui/button";
14
import { Dialog, DialogPopup, DialogTitle } from "../ui/dialog";
15
16
export function HtmlRenderDialog(props: {
17
readonly src: string;
11
- readonly title: string;
18
+ readonly htmlRender: HtmlRenderReference;
19
readonly threadRef?: ScopedThreadRef | undefined;
20
readonly onClose: () => void;
21
}) {
22
+ const { title } = props.htmlRender;
23
const [zoom, setZoom] = useState(1);
24
const closeButtonRef = useRef<HTMLButtonElement>(null);
25
+ const [width, setWidth] = useState(HTML_RENDER_COLUMN_WIDTH);
26
+ // A callback ref, since the popup can mount after this component's first commit.
27
+ const measureBox = (box: HTMLDivElement) => {
28
+ setWidth(box.clientWidth);
29
+ return observeResize(box, ([entry]) => {
30
+ // Rounded like clientWidth, so the two writes agree at fractional widths.
31
+ if (entry) setWidth(Math.round(entry.contentRect.width));
32
+ });
33
+ };
34
+ const [contentHeight, setContentHeight] = useState<number>();
35
+ // Zoom divides the page's layout width, so the page reflows to fill the card
36
+ // at every level, and the frame is as tall as the page so only the card scrolls.
37
+ const height = htmlRenderFrameHeight(props.htmlRender, width / zoom, contentHeight);
38
return (
39
<Dialog open onOpenChange={(open) => !open && props.onClose()}>
40
<DialogPopup
@@ -23,8 +44,9 @@ export function HtmlRenderDialog(props: {
44
className="row-start-1"
45
initialFocus={closeButtonRef}
46
>
26
- <DialogTitle className="sr-only">Expanded {props.title} preview</DialogTitle>
27
- <div className="relative w-[92vw]">
47
+ <DialogTitle className="sr-only">Expanded {title} preview</DialogTitle>
48
+ {/* 1144px is the widest the server measures a page; pages are written for the reply column and stretch badly beyond it. */}
49
+ <div className="relative w-[min(92vw,1176px)]">
50
<Button
51
ref={closeButtonRef}
52
aria-label="Close"
@@ -35,18 +57,21 @@ export function HtmlRenderDialog(props: {
57
>
58
<XIcon />
59
</Button>
38
- <div className="h-[min(86vh,calc(100vh-160px))] overflow-auto overscroll-contain rounded-lg bg-background p-4 shadow-2xl ring-1 ring-border/70 [container-type:size]">
39
- <div className="h-[100cqh] w-[100cqw]" style={{ zoom }}>
40
- <HtmlRenderDocument
41
- src={props.src}
42
- title={props.title}
43
- threadRef={props.threadRef}
44
- className="block size-full"
45
- />
60
+ <div className="max-h-[min(86vh,calc(100vh-160px))] overflow-y-auto overscroll-contain rounded-lg bg-background p-4 shadow-2xl ring-1 ring-border/70">
61
+ <div ref={measureBox}>
62
+ <div style={{ zoom, height }}>
63
+ <HtmlRenderDocument
64
+ src={props.src}
65
+ title={title}
66
+ threadRef={props.threadRef}
67
+ className="block size-full"
68
+ onContentHeight={setContentHeight}
69
+ />
70
+ </div>
71
</div>
72
</div>
73
<div className="mt-2 flex min-w-0 items-center justify-center gap-3 text-xs text-white/80">
49
- <span className="truncate">{props.title}</span>
74
+ <span className="truncate">{title}</span>
75
<div className="flex shrink-0 items-center gap-1">
76
<Button
77
aria-label="Zoom out"
apps/web/src/components/chat/HtmlRenderFrame.tsx
+1
-1
@@ -110,7 +110,7 @@ export function HtmlRenderFrame(props: {
110
{expandedSrc !== null ? (
111
<HtmlRenderDialog
112
src={expandedSrc}
113
- title={title}
113
+ htmlRender={props.htmlRender}
114
threadRef={props.threadRef}
115
onClose={() => setExpandedSrc(null)}
116
/>