You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix web image caching authentication issues with expo-image #83112
The BaseImage was migrated to use expo-image #83325, but it also has problems with caching if headers are provided (basically under the hood it has a really similar approach as our patch for react-native-web had). So we will need to handle it ourselves.
Update:
Today I had a spare moment and experimented with Claude a little.
It looks like the easiest way to go is to use the Cache API to cache auth images on web.
I've got a super simple hook created
useCachedImageSource
import type {ImageSource} from 'expo-image';
import {useEffect, useState} from 'react';
const CACHE_NAME = 'auth-images';
function useCachedImageSource(source: ImageSource | undefined): ImageSource | null | undefined {
const uri = typeof source === 'object' ? source?.uri : undefined;
const hasHeaders = typeof source === 'object' && !!source?.headers;
const [cachedUri, setCachedUri] = useState<string | null>(null);
useEffect(() => {
if (!hasHeaders || !uri) {
return;
}
let revoked = false;
let objectURL: string | undefined;
(async () => {
try {
const cache = await caches.open(CACHE_NAME);
const cachedResponse = await cache.match(uri);
if (cachedResponse) {
const blob = await cachedResponse.blob();
objectURL = URL.createObjectURL(blob);
if (!revoked) {
setCachedUri(objectURL);
} else {
URL.revokeObjectURL(objectURL);
}
return;
}
const response = await fetch(uri, {
headers: (source as ImageSource).headers as Record<string, string>,
});
if (!response.ok) {
throw new Error(`Failed to fetch image: ${response.status}`);
}
// Store in cache before consuming
await cache.put(uri, response.clone());
const blob = await response.blob();
objectURL = URL.createObjectURL(blob);
if (!revoked) {
setCachedUri(objectURL);
} else {
URL.revokeObjectURL(objectURL);
}
} catch {
// Fall through — cachedUri stays null, expo-image will handle it
}
})();
return () => {
revoked = true;
if (objectURL) {
URL.revokeObjectURL(objectURL);
}
};
}, [uri, hasHeaders, source]);
if (!hasHeaders) {
return source;
}
if (!cachedUri) {
return null;
}
return {uri: cachedUri};
}
export default useCachedImageSource;
I've put the hook I've mentioned in the Draft PR, so it's easier to check.
Draft PR:
pr.mp4
Production:
prod.mp4
@NJ-2020 Since you are working on #65321, what do you think? Will it overlap with your logic? Do you think it's better to wait for your PR to be merged? Cause I guess these types of updates will also touch the attachments caching, as attachments also require authentication.
cc @Julesssss
Note: I'll be OOO March 9-10 🌴 , back on March 11th
FYI: Currently in this PR (1/2) we only implement store/caching logic (libs/actions/Attachment, libs/CacheAPI), & in the next PR (2/2) we'll create a hook used for displaying the local attachment source
@NJ-2020 Since you are working on #65321, what do you think? Will it overlap with your logic? Do you think it's better to wait for your PR to be merged? Cause I guess these types of updates will also touch the attachments caching, as attachments also require authentication.
Not reallyyy, but since we already have pre-built logic regarding attachment caching, so maybe it's better to wait,
We've also done something similar before — caching remote images — though those changes were later reverted to only handle upload file attachments and markdown attachments. Here's the relevant commit / #9402 (comment).
Your work has minor overlap IMO, so I think we should go ahead with both. @VickyStash's work is a small change and immidiately enables web caching for remote images. After merging @NJ-2020's cache feature we would just have a redundant 2nd cache (local upload and then the remote image). I think that's totally fine for now and helps us ship large improvements faster. Then we can remove that that in PR 2/2 @NJ-2020?
They are separate cache's so I don't think it should affect @NJ-2020's PR 🤞 Also the time/place of cache is separate.
Your work has minor overlap IMO, so I think we should go ahead with both. @VickyStash's work is a small change and immidiately enables web caching for remote images
Updates:
I've applied codex review feedback and cleanup, but unfortunately during the testing I still found a flickering issue in the scenario when a transaction is opened for the first time (ios mweb).
Next week I'll be more focused on the FlashList migration issue, but will do my best to try to finalize the work here as well.
On Monday, I'll be OOO (Easter Monday).
In comments it says If the image fails to load, but in fact it also adds opacity until the aspect ratio is calculated.
So I'm trying to improve it in some way.
Experimenting with a changed approach - instead of preloading adjacent transactions, I'm trying a general-purpose in-memory blob cache in useCachedImageSource. Simple map (up to 20 entries) that keeps blob URLs alive after the component unmounts, so when the same image mounts again it gets the blob URL instantly without waiting for the Cache API. Images that are still on screen can't be evicted, the rest get cleaned up LRU-style when the map is full.
Also caching the aspect ratio alongside the blob - this way on re-mount the image already knows its dimensions, which should fix the shouldOpacityBeZero flash I mentioned yesterday.
Overall locally it feels better, but I need to test over all of the platforms and review with Claude/Codex
Hi there, I'm going to be OOO till 6th May 🌴
If you think it's better to re-assign this issue, please, reach out to @MrMuzyk, he will help to find someone
I'm back from vacation and returning to this issue!
Maybe I'll give one more try to maintainVisibleContentPosition.startRenderingFromBottom approach, as besides solving the issue it will give us some perf benefits (as was mentioned by @sosek108, though we ended up having some bugs there).
If no luck, I'll continue with #83112 (comment).
Hope to provide more details tomorrow!
I'll give one more try to maintainVisibleContentPosition.startRenderingFromBottom approach, as besides solving the issue it will give us some perf benefits
Activity
Julesssss commentedon Feb 20, 2026
Linked to #33725, creating this separately in case other work is required outside of FlatList migration.
VickyStash commentedon Mar 3, 2026
The
BaseImagewas migrated to use expo-image #83325, but it also has problems with caching if headers are provided (basically under the hood it has a really similar approach as our patch for react-native-web had). So we will need to handle it ourselves.[-]Improve web image caching with expo-image[/-][+]Fix web image caching authentication issues with expo-image[/+]VickyStash commentedon Mar 5, 2026
Update:
Today I had a spare moment and experimented with Claude a little.
It looks like the easiest way to go is to use the Cache API to cache auth images on web.
I've got a super simple hook created
useCachedImageSource
and then in BaseImage.tsx
Aaand it seems to work
Monosnap.screencast.2026-03-05.18-08-49.mp4
If we go this way I guess there can be some overlap with this PR work #65321, so I need to take a closer look at it
VickyStash commentedon Mar 6, 2026
Updates:
Draft PR:
pr.mp4
Production:
prod.mp4
@NJ-2020 Since you are working on #65321, what do you think? Will it overlap with your logic? Do you think it's better to wait for your PR to be merged? Cause I guess these types of updates will also touch the attachments caching, as attachments also require authentication.
cc @Julesssss
Note: I'll be OOO March 9-10 🌴 , back on March 11th
NJ-2020 commentedon Mar 6, 2026
FYI: Currently in this PR (1/2) we only implement store/caching logic (libs/actions/Attachment, libs/CacheAPI), & in the next PR (2/2) we'll create a hook used for displaying the local attachment source
Not reallyyy, but since we already have pre-built logic regarding attachment caching, so maybe it's better to wait,
We've also done something similar before — caching remote images — though those changes were later reverted to only handle upload file attachments and markdown attachments. Here's the relevant commit / #9402 (comment).
Curious to hear what others think. Thanks!
cc: @Julesssss
Julesssss commentedon Mar 7, 2026
The draft POC works very nicely for web.
Your work has minor overlap IMO, so I think we should go ahead with both. @VickyStash's work is a small change and immidiately enables web caching for remote images. After merging @NJ-2020's cache feature we would just have a redundant 2nd cache (local upload and then the remote image). I think that's totally fine for now and helps us ship large improvements faster. Then we can remove that that in PR 2/2 @NJ-2020?
They are separate cache's so I don't think it should affect @NJ-2020's PR 🤞 Also the time/place of cache is separate.
NJ-2020 commentedon Mar 7, 2026
Yeah, I think I have no issues to go with this PR
Yes, but I think it doesn't prevent the flash bug (switching from local to remote source)
I think we still need a some adjustments after merging my PR
👍
Julesssss commentedon Mar 9, 2026
@NJ-2020 ah right, thanks. But lets continue still
16 remaining items
VickyStash commentedon Apr 3, 2026
Updates:
I've applied codex review feedback and cleanup, but unfortunately during the testing I still found a flickering issue in the scenario when a transaction is opened for the first time (ios mweb).
Next week I'll be more focused on the FlashList migration issue, but will do my best to try to finalize the work here as well.
On Monday, I'll be OOO (Easter Monday).
VickyStash commentedon Apr 10, 2026
I plan to return to this one next week!
VickyStash commentedon Apr 14, 2026
Updates:
shouldOpacityBeZeroflagApp/src/components/Image/index.tsx
Lines 151 to 154 in b7b4b85
In comments it says If the image fails to load, but in fact it also adds opacity until the aspect ratio is calculated.
So I'm trying to improve it in some way.
VickyStash commentedon Apr 15, 2026
Updates:
shouldOpacityBeZeroflash I mentioned yesterday.VickyStash commentedon Apr 17, 2026
UPD: I've switched to FlashList migration deploy blockers/follow-ups. I'll return to it when I have a moment!
VickyStash commentedon Apr 23, 2026
Hi there, I'm going to be OOO till 6th May 🌴
If you think it's better to re-assign this issue, please, reach out to @MrMuzyk, he will help to find someone
VickyStash commentedon May 6, 2026
I'm back from vacation and returning to this issue!
Maybe I'll give one more try to
maintainVisibleContentPosition.startRenderingFromBottomapproach, as besides solving the issue it will give us some perf benefits (as was mentioned by @sosek108, though we ended up having some bugs there).If no luck, I'll continue with #83112 (comment).
Hope to provide more details tomorrow!
VickyStash commentedon May 7, 2026
You can check the progress here: #89768 (comment)
VickyStash commentedon May 14, 2026
Before:
before.mov
With #90218:
after.mov
Julesssss commentedon May 14, 2026
Nice, will check out the PR
VickyStash commentedon May 20, 2026
PR #90218 was deployed to prod!
VickyStash commentedon May 25, 2026
@Julesssss, I guess we can close this issue, right?
Julesssss commentedon May 26, 2026
Yeah, thanks for checking