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 23, 05:30 UTC
refactor(web): the attachment preview keeps its caching without "use memo" hooks (#20757)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 16, 2026 at 23:26 UTC
3f480b84a52f04a7b6a8cfbd1554ff730a7a5c03
1 file changed
+11
-25
apps/web/src/components/files/AttachmentFilePreview.tsx
+11
-25
@@ -48,26 +48,6 @@ 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
-
51
export function AttachmentFilePreview(props: {
52
name: string;
53
mimeType: string;
@@ -86,11 +66,17 @@ export function AttachmentFilePreview(props: {
66
kind === "markdown" ? "markdown" : kind === "html" ? "html" : delimiter ? "table" : null;
67
const attachmentId = props.asset?.attachmentId;
68
const { copyToClipboard, isCopied } = useCopyToClipboard({ target: props.name });
89
- const { resource, downloadResource } = useAttachmentResources(
90
- attachmentId,
91
- props.name,
92
- props.mimeType,
93
- );
69
+ // useAssetUrlRefresh keys its callback on these objects, so they must stay cached.
70
+ const resource = attachmentId
71
+ ? {
72
+ _tag: "attachment" as const,
73
+ attachmentId,
74
+ fileName: props.name,
75
+ mimeType: props.mimeType,
76
+ disposition: "inline" as const,
77
+ }
78
+ : null;
79
+ const downloadResource = resource ? { ...resource, disposition: "attachment" as const } : null;
80
const refresh = useAssetUrlRefresh(
81
props.file ? null : (props.asset?.environmentId ?? null),
82
props.file ? null : resource,