Skip to content
5 changes: 4 additions & 1 deletion src/components/Image/BaseImage.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import type {BaseImageProps} from './types';
function BaseImage({onLoad, source, ...props}: BaseImageProps) {
const isLoadedRef = useRef(false);
const attachmentContext = useContext(AttachmentStateContext);
const {setAttachmentLoaded} = attachmentContext || {};
const {setAttachmentLoaded, isAttachmentLoaded} = attachmentContext || {};

useEffect(() => {
if (isAttachmentLoaded?.(source as AttachmentSource)) {
return;
}
setAttachmentLoaded(source as AttachmentSource, false);
// eslint-disable-next-line react-compiler/react-compiler
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
10 changes: 7 additions & 3 deletions src/components/Image/BaseImage.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import React, {useCallback, useContext, useEffect} from 'react';
import {Image as RNImage} from 'react-native';
import type {ImageLoadEventData, ImageSourcePropType} from 'react-native';
import type {ImageLoadEvent, ImageSourcePropType} from 'react-native';
import type {AttachmentSource} from '@components/Attachments/types';
import {AttachmentStateContext} from '@pages/media/AttachmentModalScreen/AttachmentModalBaseContent/AttachmentStateContextProvider';
import type {BaseImageProps} from './types';

function BaseImage({onLoad, source, ...props}: BaseImageProps) {
const {setAttachmentLoaded} = useContext(AttachmentStateContext);
const {setAttachmentLoaded, isAttachmentLoaded} = useContext(AttachmentStateContext);
useEffect(() => {
if (isAttachmentLoaded?.(source as AttachmentSource)) {
return;
}

setAttachmentLoaded?.(source as AttachmentSource, false);
// eslint-disable-next-line react-compiler/react-compiler
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we already have logic to early return if the attachment is loaded, would it be safe to add source as a dependency of this useEffect?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it’s not safe, since we didn’t previously depend on source and this could change the effect’s behavior

const imageLoadedSuccessfully = useCallback(
(event: {nativeEvent: ImageLoadEventData}) => {
(event: ImageLoadEvent) => {
setAttachmentLoaded?.(source as AttachmentSource, true);
if (!onLoad) {
return;
Expand Down
Loading