diff --git a/studio/frontend/src/components/assistant-ui/attachment.tsx b/studio/frontend/src/components/assistant-ui/attachment.tsx index 06c7d90d07..c53c134ea2 100644 --- a/studio/frontend/src/components/assistant-ui/attachment.tsx +++ b/studio/frontend/src/components/assistant-ui/attachment.tsx @@ -26,25 +26,22 @@ import { type FC, type PropsWithChildren, useEffect, - useMemo, useState, } from "react"; import { useShallow } from "zustand/shallow"; const useFileSrc = (file: File | undefined): string | undefined => { - const objectUrl = useMemo( - () => (file ? URL.createObjectURL(file) : undefined), - [file], - ); + const [objectUrl, setObjectUrl] = useState(undefined); useEffect(() => { - if (!objectUrl) { - return undefined; + if (!file) { + setObjectUrl(undefined); + return; } - return () => { - URL.revokeObjectURL(objectUrl); - }; - }, [objectUrl]); + const url = URL.createObjectURL(file); + setObjectUrl(url); + return () => URL.revokeObjectURL(url); + }, [file]); return objectUrl; };