-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Disable image preview for invalid images #23103
base: main
Are you sure you want to change the base?
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
reviewing today |
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc: @chrispader as this logic was added in #20798
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
@@ -120,6 +121,7 @@ function AttachmentView({ | |||
loadComplete={loadComplete} | |||
isFocused={isFocused} | |||
isImage={isImage} | |||
onError={() => setIsValidImage(false)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
@@ -79,7 +79,7 @@ function AttachmentView({ | |||
isUsedInAttachmentModal, | |||
}) { | |||
const [loadComplete, setLoadComplete] = useState(false); | |||
const [imageError, setImageError] = useState(false); | |||
const [isValidImage, setIsValidImage] = useState(true); | |||
|
|||
useNetwork({onReconnect: () => setImageError(false)}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint failing
@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. |
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 Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
this
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Web
Mobile Web - Chrome
Mobile Web - Safari
Desktop
iOS
Android