Fix media re-rendering due to url object keep being recreated

This commit is contained in:
Lim Chee Aun 2023-10-12 23:19:48 +08:00
parent d1b8d737cc
commit 806ad2c6a2

View file

@ -1477,7 +1477,10 @@ function MediaAttachment({
}) { }) {
const supportsEdit = supports('@mastodon/edit-media-attributes'); const supportsEdit = supports('@mastodon/edit-media-attributes');
const { type, id, file } = attachment; const { type, id, file } = attachment;
const url = file ? URL.createObjectURL(file) : attachment.url; const url = useMemo(
() => (file ? URL.createObjectURL(file) : attachment.url),
[file, attachment.url],
);
console.log({ attachment }); console.log({ attachment });
const [description, setDescription] = useState(attachment.description); const [description, setDescription] = useState(attachment.description);
const suffixType = type.split('/')[0]; const suffixType = type.split('/')[0];