Skip to content

Commit e973e58

Browse files
refactor(web): the attachment preview keeps its caching without "use memo" hooks
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 7a08cdf commit e973e58

1 file changed

Lines changed: 11 additions & 25 deletions

File tree

‎apps/web/src/components/files/AttachmentFilePreview.tsx‎

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,6 @@ function renderedToggleLabel(mode: "markdown" | "html" | "table", rendered: bool
4848
return rendered ? "Show HTML source" : "Show rendered page";
4949
}
5050

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-
7151
export function AttachmentFilePreview(props: {
7252
name: string;
7353
mimeType: string;
@@ -86,11 +66,17 @@ export function AttachmentFilePreview(props: {
8666
kind === "markdown" ? "markdown" : kind === "html" ? "html" : delimiter ? "table" : null;
8767
const attachmentId = props.asset?.attachmentId;
8868
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;
9480
const refresh = useAssetUrlRefresh(
9581
props.file ? null : (props.asset?.environmentId ?? null),
9682
props.file ? null : resource,

0 commit comments

Comments
 (0)