Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/components/Image/BaseImage.ios.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,19 @@ function BaseImage({onLoad, source, ...props}: BaseImageProps) {
[onLoad, setAttachmentLoaded, source],
);

// Use disk caching for images that need to work offline (e.g., receipts with auth tokens)
// Use no caching for other images to avoid memory leaks
// Check if cachePolicy is explicitly provided in props, otherwise default based on whether it's an auth-required image
const effectiveCachePolicy = props.cachePolicy ?? 'none';

Choose a reason for hiding this comment

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

P2 Badge Limit iOS caching to auth images to avoid leak regression

On iOS, BaseImage now honors whatever cachePolicy callers pass, which means components that already set cachePolicy="memory-disk" (e.g., Avatar.tsx and PlaidCardFeedIcon.tsx) will start caching on iOS as well. This conflicts with the adjacent comment in this file that non‑none cache policies cause memory leaks on iOS, and there’s no new guard to keep those non‑auth images on none. If that leak is still present, this change re‑introduces it for every avatar/icon render rather than just auth‑token receipts. Consider gating non‑none cache policies to the auth‑image path or stripping cachePolicy for iOS when isAuthTokenRequired is false.

Useful? React with 👍 / 👎.


return (
<ExpoImage
// Only subscribe to onLoad when a handler is provided to avoid unnecessary event registrations, optimizing performance.
onLoad={onLoad ? imageLoadedSuccessfully : undefined}
source={source}
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
// Temporary solution only, since other cache policies are causing memory leaks on iOS
cachePolicy="none"
cachePolicy={effectiveCachePolicy}
/>
);
}
Expand Down
3 changes: 3 additions & 0 deletions src/components/Image/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ function Image({
onLoad={handleLoad}
style={[style, aspectRatioStyle, shouldOpacityBeZero && {opacity: 0}]}
source={source}
// Enable disk caching for images that require auth tokens (receipts) to make them available offline
// Keep default (none) for other images to avoid memory leaks
cachePolicy={isAuthTokenRequired ? 'disk' : forwardedProps.cachePolicy}
/>
);
}
Expand Down
Loading