Disable image preview for invalid images#23103
Conversation
|
@aimane-chnaif Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
|
@youssef-lr @MariaHCD just to confirm that we agreed to keep current file type checking logic from only file name in frontend, correct? |
Yes. There isn't a reliable way in the browser to detect the filetype other than reading first bytes from a file to detect the magic number, see this SO, and see this library which accomplishes this. The browser only decides filetypes based on the file extension so it's kind of useless. |
aimane-chnaif
left a comment
There was a problem hiding this comment.
Web looks good but not able to test native as it shows nothing in report action. Should native be fixed here or separately?
|
@youssef-lr bump on native fix |
|
Was just trying this out and after sending a corrupt image, a link preview for https://www.expensify.com/ will be added (If it doesn't come on the first image, upload the corrupt image multiple times) Screen.Recording.2023-07-28.at.3.11.37.PM.mp4 |
|
@huzaifa-99 that makes sense and isn't a bug, it the image is invalid the URL preview will appear because it is treated like a link. @aimane-chnaif checking the native issue now. |
|
Just pushed a fix @aimane-chnaif |
|
bump @aimane-chnaif :) |
|
@youssef-lr please fix conflict |
|
On it, looks like |
7af2fe8 to
c802b8c
Compare
| @@ -95,7 +96,7 @@ function AttachmentView({ | |||
| // For this check we use both source and file.name since temporary file source is a blob | |||
| // both PDFs and images will appear as images when pasted into the the text field | |||
| const isImage = Str.isImage(source); | |||
There was a problem hiding this comment.
@aimane-chnaif I wonder why this isn't ìsImage = Str.isImage(source) || (file && Str.isImage(file.name)) then next we can just use if (isImage && isValidImage), am I missing something on why this could be intentional?
There was a problem hiding this comment.
cc: @chrispader as this logic was added in #20798
There was a problem hiding this comment.
I was actually just taking over the original logic from the previous code: https://github.com/margelo/expensify-app-fork/blob/9fa8c89b095d88b4066f209c16d34e3ee261e991/src/components/AttachmentView.js#L105-L106
I think the difference here is that we first check if the source is an image, else if there is a file prop and if that's an image. Not sure if this is intentional though, so i think somebody else has to answer this question. :)
|
@youssef-lr conflicts again |
|
@youssef-lr bump |
| loadComplete={loadComplete} | ||
| isFocused={isFocused} | ||
| isImage={isImage} | ||
| onError={() => setIsValidImage(false)} |
There was a problem hiding this comment.
Receiving onError callback doesn't always mean that image is invalid.
i.e. when offline:
Screen.Recording.2023-08-27.at.5.50.53.PM.mov
There was a problem hiding this comment.
Looking into this
|
@youssef-lr Is there any update on this issue? |
|
@MariaHCD @youssef-lr @sonialiap @aimane-chnaif Could anyone update us the (beneficiary contributors) the status of this and related issues? Because we're looking for updates on this issue for more than 3 months. @youssef-lr this issue also delaying the #19728 for over 3 months going to be 4 months after 7 days. Any update? |
|
@KALLL Expensifiers are all currently working on higher priority projects and issues so this one is falling off our radar. @youssef-lr, since your plate is full, let's consider having a contributor take over instead? |
|
@youssef-lr kindly bump ^ |
|
@youssef-lr can we open this for contributors? |
|
Working on finishing up this PR now |
|
@aimane-chnaif I can't reproduce the |
|
@youssef-lr please merge main and fix conflict. I will test again based on latest codebase |
| const [imageError, setImageError] = useState(false); | ||
| const [isValidImage, setIsValidImage] = useState(true); | ||
|
|
||
| useNetwork({onReconnect: () => setImageError(false)}); |
|
@youssef-lr to reproduce, image should not be locally cached. Test in fresh browser, i.e. incognito Screen.Recording.2023-11-03.at.11.13.01.PM.movAlso, another weird thing is that image (i.e. workspace avatar) is treated as file attachment Screen.Recording.2023-11-03.at.11.12.06.PM.mov |
|
Updated @aimane-chnaif, both issues should be fixed now hopefully! |
|
Please check video (main vs this branch). Both issues still happening (isImage: true, isValidImage: false, fallbackSource: undefined) Screen.Recording.2023-11-05.at.7.54.06.AM.mov |
|
I think we should confirm the expected page when preview "not cached image" when offline
Screen.Recording.2023-11-05.at.8.03.14.AM.mov
Screen.Recording.2023-11-05.at.8.02.26.AM.movcc: @Expensify/design |
|
I mean it makes sense as we're trying to fetch the full size image from the server but we're offline. How about we display an error message like 'unable to load image'? |
Kind of agree as it's aligned with PDF preview in offline mode |
|
Hmm I have the infinite loading with the changes from this PR, i.e. I don't see the link to the image as you do. One issue I found is that as soon as I disable internet the thumbnail disappears, even though it's already loaded which I think shouldn't happen. Screen.Recording.2023-11-05.at.16.39.07.mov |
|
Please follow step I did. 100% reproducible
Screen.Recording.2023-11-05.at.1.46.56.PM.mov |
|
I agree that it'd be nice align on the offline behavior—I like the idea of mimicking what we do with PDFs and showing the "Unable to load whatever" while offline. cc @Expensify/design |
|
Heads up I'm OOO for a couple of days and I might not reply in a timely manner. I'll still probably finish this PR in a couple of days. |
|
Is there any update on this issue? @youssef-lr @aimane-chnaif or incase it is resolved it should be closed. |
|
I think we can close this for now. |


Details
cc @MariaHCD
Fixed Issues
$ #19728
Tests
.jpg, for example a txt document.Offline tests
QA Steps
.jpg, for example a txt document.PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)myBool && <MyComponent />.src/languages/*files and using the translation methodWaiting for Copylabel for a copy review on the original GH to get the correct copy.STYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)/** comment above it */thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor)thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG))Avataris modified, I verified thatAvataris working as expected in all cases)ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Web
Mobile Web - Chrome
Mobile Web - Safari
Desktop
iOS
Android