thunder-app / thunder

Thunder - An open-source cross-platform Lemmy client for iOS and Android built with Flutter
https://thunderapp.dev
GNU Affero General Public License v3.0
779 stars 67 forks source link

Jpeg XL breaks things pretty badly. #1073

Closed cooperaj closed 6 months ago

cooperaj commented 8 months ago

Description JPEG XL (JXL) images cause Thunder to break output. They're not technically supported by Pictrs so are not used often.

How to Reproduce
Steps to reproduce the behavior:

  1. Go to https://lemmy.world/post/11021604
  2. Screen briefly loads then changes to an empty black screen

Expected Behavior
Even if the image fails the comment thread should still be visible.

Device & App Version:

micahmo commented 8 months ago

I wonder if we'd need to open an issue with Extended Image.

hjiangsu commented 8 months ago

Interesting - it looks like it renders properly on iOS (which coincidentally relates to the meme 😆)

IMG_1575

hjiangsu commented 8 months ago

@micahmo are you able to get the specific error that occurs when trying to load a jpeg xl image?

micahmo commented 8 months ago

I'm not sure if it helps, but an exception is thrown here.

image

And here is the call stack.

image

And although it's not in the stack, I assume this comes back to an ExtendedImage.network constructor.

hjiangsu commented 8 months ago

So I took a deeper look into this, and it seems like this may be out of scope to support jxl at this moment. Flutter itself does not support jxl as mentioned here: https://github.com/flutter/flutter/issues/113476. Flutter does provide fallback to using the OS's media codecs so it depends on the OS. For example, Apple currently has support for jxl but Android still has an open issue for this: https://issuetracker.google.com/issues/259900694?pli=1

It seems like the only solutions here are to either create a jxl codec plugin, or have some resolution on Android's end to implement support for jxl.

What we can do, is add in a check to see if its jxl, and either fallback to showing an error, or request the image in a different format using ?format= for the pictrs endpoint (e.g., ?format=png or ?format=jpeg.

hjiangsu commented 7 months ago

Just a quick update on this, I've fixed the issue where the comment section breaks when attempting to load a failed image. This handles the more generic case where unsupported formats should fallback gracefully.

In terms of providing support for jxl, that may come in the future. The problem with my suggestion previously is that not all images may come from pictrs, so some additional thought will be needed to come up with a more robust solution.

That being said, since pictrs does not technically support jxl, I dont believe there will be too many instances of this happening so we can revisit jxl support in the future (and maybe then, it'll be more widely adopted!)