Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to reload image when error occurs #25

Open
bradstiff opened this issue Nov 16, 2024 · 1 comment
Open

Unable to reload image when error occurs #25

bradstiff opened this issue Nov 16, 2024 · 1 comment

Comments

@bradstiff
Copy link

bradstiff commented Nov 16, 2024

I am displaying images in a FlatList. In low network conditions, some of those images are blank, and some are the default Broken Image that is part of this package.

On Android, if I open a detail page with another instance of BlastedImage with the exact same image URI, and the image loads, I can then return to the previous page (which has not been unmounted / remounted), but the image is still broken. The image is only repaired by unmounting / remounting the FlatList.

If I recall correctly, with react-native-fast-image, if a broken image were eventually loaded successfully, it would then appear on every mounted image instance with the same URI.

I will dig into the react-native-fast-image code to see if it was doing something that caused the above auto-repair behavior.

Otherwise, I am considering keeping track of the broken images via onError. If the FlatList is manually refreshed by the user via pull down refresh, I will call the exported loadImage on each broken one and then generate a new key for the corresponding BlastedImage component to force it to remount. I expect this will fix the issue.

Is there a better way to force reloading of the images that initially failed?

@bradstiff
Copy link
Author

bradstiff commented Nov 21, 2024

After further investigation into this package, I discovered the following.

When an image fails to load due to a network timeout or invalid url, the error state value is set and the component renders image-error.png.

Sending a new instance of the source object prop has no impact, because the effect that fetches the image returns early when the error state value is set.

Removing the error state value from the effect dependency causes an infinite rendering loop because the source prop is modified by the component itself (e.g., not a stable value).

So there is no way to retry fetching the image other than unmounting and remounting.

@bradstiff bradstiff changed the title Best practice to force reload in low network conditions Unable to reload image when error occurs Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant