From ad402ff456e9258adb01773604f7f36ff9d955d2 Mon Sep 17 00:00:00 2001 From: Henry-Hiles Date: Wed, 18 Nov 2026 11:09:36 -0500 Subject: [PATCH] don't cache fetch failures for media --- lib/helpers/mxc_image.dart | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/helpers/mxc_image.dart b/lib/helpers/mxc_image.dart index 4013397..15c4328 100644 --- a/lib/helpers/mxc_image.dart +++ b/lib/helpers/mxc_image.dart @@ -20,18 +20,23 @@ class MxcImage(final WidgetRef ref, final DownloadMediaRequest request) MultiFrameImageStreamCompleter(codec: _loadAsync(decode), scale: 1.0); Future _loadAsync(ImageDecoderCallback decode) async { - final file = await ref - .read(ClientController.provider.notifier) - .downloadMedia(request); - final bytes = await File(file.path).readAsBytes(); + try { + final file = await ref + .read(ClientController.provider.notifier) + .downloadMedia(request); + final bytes = await File(file.path).readAsBytes(); - // Flutter can't decode AVIF on Linux/Windows (or older Android/iOS), so we do it ourselves - if (String.fromCharCodes(bytes.skip(4).take(8)) - case "ftypavif" || "ftypavis") { - return AvifCodec(await Isolate.run(() => decodeAvif(bytes))); + // Flutter can't decode AVIF on Linux/Windows (or older Android/iOS), so we do it ourselves + if (String.fromCharCodes(bytes.skip(4).take(8)) + case "ftypavif" || "ftypavis") { + return AvifCodec(await Isolate.run(() => decodeAvif(bytes))); + } + + return await decode(await .fromUint8List(bytes)); + } catch (_) { + scheduleMicrotask(() => PaintingBinding.instance.imageCache.evict(this)); + rethrow; } - - return decode(await .fromUint8List(bytes)); } @override