Skip to content

Commit 2c7d3ce

Browse files
authored
fix: regenerate image preview URL on image attachment removal when editing a message (#2775)
1 parent a87f500 commit 2c7d3ce

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/components/Attachment/AttachmentContainer.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,19 @@ export const GalleryContainer = ({
109109
>([]);
110110

111111
useLayoutEffect(() => {
112-
if (
113-
imageElements.current &&
114-
imageElements.current.every((element) => !!element) &&
115-
imageAttachmentSizeHandler
116-
) {
117-
const newConfigurations: ImageAttachmentConfiguration[] = [];
118-
imageElements.current.forEach((element, i) => {
119-
const config = imageAttachmentSizeHandler(attachment.images[i], element);
120-
newConfigurations.push(config);
121-
});
122-
setAttachmentConfigurations(newConfigurations);
112+
if (!imageElements.current || !imageAttachmentSizeHandler) return;
113+
const newConfigurations: ImageAttachmentConfiguration[] = [];
114+
const nonNullImageElements = imageElements.current.filter((e) => !!e);
115+
if (nonNullImageElements.length < imageElements.current.length) {
116+
imageElements.current = nonNullImageElements;
123117
}
124-
}, [imageElements, imageAttachmentSizeHandler, attachment]);
118+
imageElements.current.forEach((element, i) => {
119+
if (!element) return;
120+
const config = imageAttachmentSizeHandler(attachment.images[i], element);
121+
newConfigurations.push(config);
122+
});
123+
setAttachmentConfigurations(newConfigurations);
124+
}, [imageAttachmentSizeHandler, attachment]);
125125

126126
const images = attachment.images.map((image, i) => ({
127127
...image,

0 commit comments

Comments
 (0)