@devries-cameron20 / t3code-1 / commits / 70e4319da8
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): switching back to a thread no longer jumps through its HTML renders (#38458)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Pouya Rezvani committed Nov 17, 2026 at 22:36 UTC 70e4319da82f75240cba6b47956e77b5bde611ee
2 files changed +64 -4
apps/web/src/components/chat/HtmlRenderFrame.browser.test.tsx
+44 -2
@@ -3,12 +3,14 @@ import { describe, expect, it, vi } from "vite-plus/test";
3 import { userEvent } from "vite-plus/test/browser";
4
5 import "~/index.css";
6 -import { render } from "../../../test/render";
6 +import { render, type Screen } from "../../../test/render";
7 +
8 +const assetUrl = vi.hoisted(() => ({ current: "about:blank" }));
9
10 vi.mock(import("~/assets/longLivedAssetUrls"), () => ({
11 useLongLivedAssetUrl: () => ({
12 _tag: "Success",
11 - url: "about:blank",
13 + url: assetUrl.current,
14 expiresAt: Date.now() + 60 * 60_000,
15 }),
16 }));
@@ -19,8 +21,19 @@ vi.mock(import("~/assets/assetUrls"), async (importOriginal) => ({
21
22 import { HtmlRenderFrame } from "./HtmlRenderFrame";
23
24 +function setup() {
25 + assetUrl.current = "about:blank";
26 +}
27 +
28 +const sizeChanged = (height: number) => ({
29 + jsonrpc: "2.0",
30 + method: "ui/notifications/size-changed",
31 + params: { height },
32 +});
33 +
34 describe("HtmlRenderFrame", () => {
35 it("reports leaving full screen when it unmounts while expanded", async () => {
36 + setup();
37 const onFullscreenChange = vi.fn();
38 await using screen = await render(
39 <HtmlRenderFrame
@@ -38,4 +51,33 @@ describe("HtmlRenderFrame", () => {
51 await screen.unmount();
52 expect(onFullscreenChange).toHaveBeenLastCalledWith(false);
53 });
54 +
55 + it("reopens at the page height it last measured", async () => {
56 + setup();
57 + using page = (() => {
58 + const html = `<script>parent.postMessage(${JSON.stringify(sizeChanged(1500))}, "*");</script>`;
59 + const url = URL.createObjectURL(new Blob([html], { type: "text/html" }));
60 + return { url, [Symbol.dispose]: () => URL.revokeObjectURL(url) };
61 + })();
62 + const frame = () => (
63 + <HtmlRenderFrame
64 + environmentId={EnvironmentId.make("environment")}
65 + htmlRender={{ attachmentId: "measured", title: "Mockup", height: 200 }}
66 + threadRef={undefined}
67 + />
68 + );
69 + const frameHeight = (screen: Screen) =>
70 + screen.getByTitle("Mockup").element().parentElement?.style.height;
71 +
72 + assetUrl.current = page.url;
73 + {
74 + await using first = await render(frame());
75 + await vi.waitFor(() => expect(frameHeight(first)).toBe("1500px"));
76 + }
77 +
78 + // A page that never reports its height, so only the remembered measurement can size the frame.
79 + assetUrl.current = "about:blank";
80 + await using second = await render(frame());
81 + expect(frameHeight(second)).toBe("1500px");
82 + });
83 });
apps/web/src/components/chat/HtmlRenderFrame.tsx
+20 -2
@@ -20,6 +20,19 @@ import { HtmlRenderDialog } from "./HtmlRenderDialog";
20 import { observeResize } from "~/lib/observeResize";
21
22 const MIN_URL_LIFE_MS = 5 * 60_000;
23 +const MAX_MEASURED_CONTENT_HEIGHTS = 200;
24 +
25 +// The height each render's page last reported, so a remounted frame opens at it before its page loads.
26 +const measuredContentHeights = new Map<string, number>();
27 +
28 +function rememberContentHeight(attachmentId: string, height: number) {
29 + measuredContentHeights.delete(attachmentId);
30 + measuredContentHeights.set(attachmentId, height);
31 + if (measuredContentHeights.size > MAX_MEASURED_CONTENT_HEIGHTS) {
32 + const oldest = measuredContentHeights.keys().next().value;
33 + if (oldest !== undefined) measuredContentHeights.delete(oldest);
34 + }
35 +}
36
37 export function HtmlRenderFrame(props: {
38 readonly environmentId: EnvironmentId;
@@ -37,7 +50,9 @@ export function HtmlRenderFrame(props: {
50 });
51 };
52 // Client fonts can exceed the server-measured height and cause nested scrolling.
40 - const [contentHeight, setContentHeight] = useState<number>();
53 + const [contentHeight, setContentHeight] = useState(() =>
54 + measuredContentHeights.get(attachmentId),
55 + );
56 const height = htmlRenderFrameHeight(props.htmlRender, width, contentHeight);
57 const fileName = htmlRenderFileName(title);
58 const resource = {
@@ -77,7 +92,10 @@ export function HtmlRenderFrame(props: {
92 title={title}
93 threadRef={props.threadRef}
94 className="block size-full"
80 - onContentHeight={setContentHeight}
95 + onContentHeight={(height) => {
96 + rememberContentHeight(attachmentId, height);
97 + setContentHeight(height);
98 + }}
99 onFullscreenChange={onFullscreenChange}
100 />
101 <div className="absolute end-2 top-2 flex gap-1 opacity-0 transition-opacity duration-150 focus-within:opacity-100 group-hover/html-render:opacity-100 pointer-coarse:opacity-100">