@devries-cameron20 / t3code Mirror · read-only / commits / 0bf4787269
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 23:15 UTC

fix(web): preserve HTML input when preview URLs renew (#17736)

Co-authored-by: Julius Marminge <julius0216@outlook.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>

Joël Deffner committed Oct 20, 2026 at 06:20 UTC 0bf47872691077b3de7b84c19f43462d0554d22e
3 files changed +54 -5
apps/web/src/components/files/BrowserDocumentFrame.browser.test.tsx new
+39
@@ -0,0 +1,39 @@
1 +import { act } from "react";
2 +import { createRoot } from "react-dom/client";
3 +import { expect, it, onTestFinished, vi } from "vite-plus/test";
4 +
5 +import { BrowserDocumentFrame } from "./BrowserDocumentFrame";
6 +
7 +it("keeps the loaded HTML page while its signed URL renews, and reloads on a new revision", async () => {
8 + vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
9 + const container = document.createElement("div");
10 + document.body.append(container);
11 + const root = createRoot(container);
12 + onTestFinished(async () => {
13 + await act(async () => root.unmount());
14 + container.remove();
15 + vi.unstubAllGlobals();
16 + });
17 + const render = (src: string, documentKey?: string) =>
18 + act(async () =>
19 + root.render(
20 + <BrowserDocumentFrame src={src} title="Review" pdf={false} documentKey={documentKey} />,
21 + ),
22 + );
23 +
24 + await render("about:blank#token-a", "review.html:1");
25 + const frame = container.querySelector("iframe");
26 + await render("about:blank#token-b", "review.html:1");
27 + expect(container.querySelector("iframe")).toBe(frame);
28 + expect(frame?.getAttribute("src")).toBe("about:blank#token-a");
29 +
30 + await render("about:blank#token-c", "review.html:2");
31 + expect(container.querySelector("iframe")).not.toBe(frame);
32 + expect(container.querySelector("iframe")?.getAttribute("src")).toBe("about:blank#token-c");
33 +
34 + await render("about:blank#first");
35 + const urlDrivenFrame = container.querySelector("iframe");
36 + await render("about:blank#second");
37 + expect(container.querySelector("iframe")).not.toBe(urlDrivenFrame);
38 + expect(container.querySelector("iframe")?.getAttribute("src")).toBe("about:blank#second");
39 +});
apps/web/src/components/files/BrowserDocumentFrame.tsx
+14 -5
@@ -71,8 +71,10 @@ export function BrowserDocumentFrame(props: {
71 readonly pdf: boolean;
72 readonly htmlRender?: boolean;
73 readonly threadRef?: ScopedThreadRef | undefined;
74 + /** Stable resource identity and revision; defaults to src for callers that reload on URL changes. */
75 + readonly documentKey?: string | undefined;
76 }) {
75 - const className = "min-h-0 flex-1 border-0 bg-white";
77 + const key = props.documentKey ?? props.src;
78 return props.pdf ? (
79 <embed
80 key={props.src}
@@ -83,18 +85,25 @@ export function BrowserDocumentFrame(props: {
85 />
86 ) : props.htmlRender ? (
87 <HtmlRenderDocument
86 - key={props.src}
88 + key={key}
89 src={props.src}
90 title={props.title}
91 threadRef={props.threadRef}
92 className="min-h-0 flex-1"
93 />
94 ) : (
95 + <FileDocument key={key} src={props.src} title={props.title} />
96 + );
97 +}
98 +
99 +// URL renewals must not discard form input or scroll; a new key mounts a fresh document.
100 +function FileDocument(props: { readonly src: string; readonly title: string }) {
101 + const [src] = useState(props.src);
102 + return (
103 <iframe
94 - key={props.src}
95 - src={props.src}
104 + src={src}
105 title={props.title}
97 - className={className}
106 + className="min-h-0 flex-1 border-0 bg-white"
107 sandbox="allow-scripts allow-forms allow-popups allow-downloads"
108 />
109 );
apps/web/src/components/files/FilePreviewPanel.tsx
+1
@@ -257,6 +257,7 @@ function WorkspaceBrowserPreview(props: {
257 return (
258 <BrowserDocumentFrame
259 src={`${assetUrl.url}${revisionSuffix}`}
260 + documentKey={`${props.environmentId}:${resource._tag}:${props.threadRef.threadId}:${props.absolutePath}:${props.workspaceMutationId}`}
261 title={props.title}
262 pdf={isPdfPreviewFile(props.absolutePath)}
263 />