@devries-cameron20 / t3code-1 / commits / 426706cbce
Fork 0

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

perf(web): the attachment file preview compiles with the React Compiler (#20479)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 16, 2026 at 18:46 UTC 426706cbcec497054c688ecc4e45e6d1bbc2a8c2
2 files changed +52 -42
apps/web/reactCompiledFiles.ts
+1
@@ -54,4 +54,5 @@ export const REACT_COMPILED_FILES = [
54 "apps/web/src/components/preview/PreviewView.tsx",
55 "apps/web/src/components/CommandPalette.tsx",
56 "apps/web/src/components/ServerUpdateAction.tsx",
57 + "apps/web/src/components/files/AttachmentFilePreview.tsx",
58 ] as const;
apps/web/src/components/files/AttachmentFilePreview.tsx
+51 -42
@@ -2,10 +2,13 @@ import { filePreviewDelimiter } from "@t3tools/shared/delimitedPreview";
2 import type { EnvironmentId, ScopedThreadRef } from "@t3tools/contracts";
3 import { formatAttachmentSize } from "@t3tools/client-runtime/state/attachments";
4 import { readFilePreviewResponse } from "@t3tools/client-runtime/file-preview";
5 +import { settlePromise } from "@t3tools/client-runtime/state/runtime";
6 +import * as AsyncResult from "effect/reactivity/AsyncResult";
7 +import * as Cause from "effect/Cause";
8 import { filePreviewKind, FILE_TEXT_PREVIEW_MAX_BYTES } from "@t3tools/shared/filePreview";
9 import { ChevronRightIcon, DownloadIcon, Trash2Icon, WrapTextIcon, XIcon } from "lucide-react";
10 import { Check, Code2, Copy, Eye, Table2 } from "lucide";
8 -import { lazy, Suspense, useEffect, useMemo, useRef, useState } from "react";
11 +import { lazy, Suspense, useEffect, useRef, useState } from "react";
12
13 import { useAssetUrlRefresh } from "~/assets/assetUrls";
14 import ChatMarkdown from "~/components/ChatMarkdown";
@@ -45,6 +48,26 @@ function renderedToggleLabel(mode: "markdown" | "html" | "table", rendered: bool
48 return rendered ? "Show HTML source" : "Show rendered page";
49 }
50
51 +// useAssetUrlRefresh keys its callback on these objects, so they must stay cached.
52 +function useAttachmentResources(
53 + attachmentId: string | undefined,
54 + fileName: string,
55 + mimeType: string,
56 +) {
57 + "use memo";
58 + const resource = attachmentId
59 + ? {
60 + _tag: "attachment" as const,
61 + attachmentId,
62 + fileName,
63 + mimeType,
64 + disposition: "inline" as const,
65 + }
66 + : null;
67 + const downloadResource = resource ? { ...resource, disposition: "attachment" as const } : null;
68 + return { resource, downloadResource };
69 +}
70 +
71 export function AttachmentFilePreview(props: {
72 name: string;
73 mimeType: string;
@@ -63,27 +86,15 @@ export function AttachmentFilePreview(props: {
86 kind === "markdown" ? "markdown" : kind === "html" ? "html" : delimiter ? "table" : null;
87 const attachmentId = props.asset?.attachmentId;
88 const { copyToClipboard, isCopied } = useCopyToClipboard({ target: props.name });
66 - const resource = useMemo(
67 - () =>
68 - attachmentId
69 - ? {
70 - _tag: "attachment" as const,
71 - attachmentId,
72 - fileName: props.name,
73 - mimeType: props.mimeType,
74 - disposition: "inline" as const,
75 - }
76 - : null,
77 - [attachmentId, props.name, props.mimeType],
89 + const { resource, downloadResource } = useAttachmentResources(
90 + attachmentId,
91 + props.name,
92 + props.mimeType,
93 );
94 const refresh = useAssetUrlRefresh(
95 props.file ? null : (props.asset?.environmentId ?? null),
96 props.file ? null : resource,
97 );
83 - const downloadResource = useMemo(
84 - () => (resource ? { ...resource, disposition: "attachment" as const } : null),
85 - [resource],
86 - );
98 const prepareDownload = useAssetUrlRefresh(props.asset?.environmentId ?? null, downloadResource);
99 const [saving, setSaving] = useState(false);
100 const [localUrl, setLocalUrl] = useState<string | null>(null);
@@ -172,37 +183,35 @@ export function AttachmentFilePreview(props: {
183
184 const save = () => {
185 setSaving(true);
175 - void (async () => {
176 - try {
177 - let file = props.file;
178 - if (!file) {
179 - const target = await prepareDownload();
180 - if (!target) throw new Error("Reconnect to the environment and try again.");
181 - const response = await fetch(target);
182 - if (!response.ok) throw new Error("The file could not be loaded. Try again.");
183 - file = await response.blob();
184 - }
185 - // A Blob keeps cross-origin downloads inside the desktop client instead of
186 - // navigating its custom app scheme to an external browser.
187 - const downloadUrl = URL.createObjectURL(file);
188 - try {
189 - const anchor = document.createElement("a");
190 - anchor.href = downloadUrl;
191 - anchor.download = props.name;
192 - anchor.click();
193 - } finally {
194 - setTimeout(() => URL.revokeObjectURL(downloadUrl), 30_000);
195 - }
196 - } catch (cause) {
186 + void settlePromise(async () => {
187 + let file = props.file;
188 + if (!file) {
189 + const target = await prepareDownload();
190 + if (!target) throw new Error("Reconnect to the environment and try again.");
191 + const response = await fetch(target);
192 + if (!response.ok) throw new Error("The file could not be loaded. Try again.");
193 + file = await response.blob();
194 + }
195 + // A Blob keeps cross-origin downloads inside the desktop client instead of
196 + // navigating its custom app scheme to an external browser.
197 + const downloadUrl = URL.createObjectURL(file);
198 + // Scheduled before the click so the URL is revoked even if the click throws.
199 + setTimeout(() => URL.revokeObjectURL(downloadUrl), 30_000);
200 + const anchor = document.createElement("a");
201 + anchor.href = downloadUrl;
202 + anchor.download = props.name;
203 + anchor.click();
204 + }).then((result) => {
205 + if (!AsyncResult.isSuccess(result)) {
206 + const cause = Cause.squash(result.cause);
207 toastManager.add({
208 type: "error",
209 title: "Could not save file",
210 description: cause instanceof Error ? cause.message : "Please try again.",
211 });
202 - } finally {
203 - setSaving(false);
212 }
205 - })();
213 + setSaving(false);
214 + });
215 };
216
217 const body = failure ? (