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

[HOLD for payment 2024-01-04] [HOLD for payment 2024-01-03] [$500] Chat - PDF is not displayed in chat after uploading #33626

Closed
2 of 6 tasks
kbecciv opened this issue Dec 26, 2023 · 40 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 Engineering External Added to denote the issue can be worked on by a contributor

Comments

@kbecciv
Copy link

kbecciv commented Dec 26, 2023

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 1.4.17-1
Reproducible in staging?: y
Reproducible in production?: n
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: Applause - Internal Team
Slack conversation:

Action Performed:

Pre-requisite: the user must be logged in.

  1. Go to any chat.
  2. Tap on the "+" button.
  3. Tap on "Add attachment".
  4. Tap on "Choose document".
  5. Select any PDF.
  6. Tap on "Send".
  7. Wait for it to upload.

Expected Result:

PDF preview should be displayed in chat after the uploading.

Actual Result:

PDF preview is not displayed in chat after the uploading.

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence

Bug6326434_1703625657812.Chox1648_1_.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01a3278ab046cf0de8
  • Upwork Job ID: 1739768322479259648
  • Last Price Increase: 2023-12-26
  • Automatic offers:
    • mkhutornyi | Contributor | 28070768
Issue OwnerCurrent Issue Owner: @parasharrajat
@kbecciv kbecciv added the DeployBlockerCash This issue or pull request should block deployment label Dec 26, 2023
Copy link
Contributor

👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:

  1. Identify the pull request that introduced this issue and revert it.
  2. Find someone who can quickly fix the issue.
  3. Fix the issue yourself.

Copy link

melvin-bot bot commented Dec 26, 2023

Triggered auto assignment to @Beamanator (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.

@kbecciv
Copy link
Author

kbecciv commented Dec 26, 2023

Issue is not reproduced on production

RPReplay_Final1703624381.MP4

@mountiny mountiny added the External Added to denote the issue can be worked on by a contributor label Dec 26, 2023
Copy link

melvin-bot bot commented Dec 26, 2023

Job added to Upwork: https://www.upwork.com/jobs/~01a3278ab046cf0de8

@melvin-bot melvin-bot bot changed the title Chat - PDF is not displayed in chat after uploading [$500] Chat - PDF is not displayed in chat after uploading Dec 26, 2023
@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Dec 26, 2023
Copy link

melvin-bot bot commented Dec 26, 2023

Triggered auto assignment to Contributor-plus team member for initial proposal review - @parasharrajat (External)

@mountiny
Copy link
Contributor

I think this might be related to the expo image pr #30905 and seems like a true blocker as PDF files cannot be used/ sent in native devices cc @WojtekBoman

@mountiny
Copy link
Contributor

The PDF previews are missing even after coming back to the chat so definitely a blocker imho

@Beamanator
Copy link
Contributor

holy monkeys that's a big diff 😅

Would be great if @WojtekBoman could help investigate this 🙏 I'll try to test locally soon, assuming my sims start up nicely

@mkhutornyi
Copy link
Contributor

mkhutornyi commented Dec 27, 2023

Proposal

Please re-state the problem that we are trying to solve in this issue.

PDF preview is not displayed in chat

What is the root cause of that problem?

This is html attribute:
<img src="https://www.expensify.com/chat-attachments/:reportID/test.jpg.1024.jpg" data-expensify-source="https://www.expensify.com/chat-attachments/:reportID/test.pdf" data-name="001.pdf" data-expensify-height="0" data-expensify-width="0" />

We check data-expensify-height and data-expensify-width here:

const imageWidth = htmlAttribs['data-expensify-width'] ? parseInt(htmlAttribs['data-expensify-width'], 10) : undefined;
const imageHeight = htmlAttribs['data-expensify-height'] ? parseInt(htmlAttribs['data-expensify-height'], 10) : undefined;

As "0" is not falsy, it doesn't meet above condition and imageWidth, imageHeight are set to undefined.
And they're passed to ThumbnailImage component:

<ThumbnailImage
previewSourceURL={previewSource}
style={styles.webViewStyles.tagStyles.img}
isAuthTokenRequired={isAttachmentOrReceipt}
imageWidth={imageWidth}
imageHeight={imageHeight}
/>

In ThumbnailImage, there's default value of 200 but as it's already set to "0", the default value is ignored

function ThumbnailImage({previewSourceURL, style, isAuthTokenRequired, imageWidth = 200, imageHeight = 200, shouldDynamicallyResize = true}: ThumbnailImageProps) {

What changes do you think we should make in order to solve the problem?

const imageWidth = htmlAttribs['data-expensify-width'] ? parseInt(htmlAttribs['data-expensify-width'], 10) : undefined;
const imageHeight = htmlAttribs['data-expensify-height'] ? parseInt(htmlAttribs['data-expensify-height'], 10) : undefined;

We can update this condition so check "0" as well:

- const imageWidth = htmlAttribs['data-expensify-width'] ? parseInt(htmlAttribs['data-expensify-width'], 10) : undefined;
- const imageHeight = htmlAttribs['data-expensify-height'] ? parseInt(htmlAttribs['data-expensify-height'], 10) : undefined;
+ const imageWidth = +htmlAttribs['data-expensify-width'] ? parseInt(htmlAttribs['data-expensify-width'], 10) : undefined;
+ const imageHeight = +htmlAttribs['data-expensify-height'] ? parseInt(htmlAttribs['data-expensify-height'], 10) : undefined;

(+ operator converts string to number so "0" ? is changed to 0 ?)

@Beamanator
Copy link
Contributor

Hmm @mkhutornyi I like your idea, but i think we need to know why this is now necessary - a.k.a. what's different in prod now & how did things change?

@mountiny
Copy link
Contributor

I am afraid the SWM developers will be ooo mostly so we should not wait for them. @mkhutornyi could you pinpoint whats the rootcause of this being different in staging than in production? thanks!

@mkhutornyi
Copy link
Contributor

mkhutornyi commented Dec 27, 2023

Before, we used FastImage and onLoad callback was called even when width/height layout is not set.
But expo image doesn't seem to send onLoad callback when size is 0

onLoad={imageLoadedSuccessfully}

This is supposed to call updateImageSize which resize image to correct width/height:

const updateImageSize = useCallback(
({width, height}: UpdateImageSizeParams) => {
const {thumbnailWidth, thumbnailHeight} = calculateThumbnailImageSize(width, height, windowHeight);
setCurrentImageWidth(thumbnailWidth);
setCurrentImageHeight(thumbnailHeight);
},
[windowHeight],
);

@mkhutornyi
Copy link
Contributor

mkhutornyi commented Dec 27, 2023

My solution still has issue of showing default size (200, 200) briefly before getting correct size.
In production, it's not completely shown before getting correct size.
But, this should at least unblock deploy

@kevinpetersson
Copy link

It seems like you are facing an issue where the default size (200, 200) is briefly shown before getting the correct size when using the updateImageSize function. I think the solution is to set an initial state for thumbnailWidth and tumbnailHeight before calculating and updating them. In this way, the
component rendering will have the correct initial values before the asynchronous calculation completes.

Here is my answer.

const updateImageSize = useCallback(
  async ({ width, height }: UpdateImageSizeParams) => {
    // Set initial values to the default size
    let thumbnailWidth = 200;
    let thumbnailHeight = 200;

    // Calculate the thumbnail size asynchronously
    const { thumbnailWidth: calculatedWidth, thumbnailHeight: calculatedHeight } = await calculateThumbnailImageSize(
      width,
      height,
      windowHeight
    );

    // Update the state with the correct size
    thumbnailWidth = calculatedWidth;
    thumbnailHeight = calculatedHeight;

    setCurrentImageWidth(thumbnailWidth);
    setCurrentImageHeight(thumbnailHeight);
  },
  [windowHeight],
);

In this code, by setting the initial values before the asynchronous calculation, you ensure that the default size is set before the component renders. The await keyword is used to wait for the asynchronous calculation to complete before updating the state with the correct size.

(I have assume that calculate ThumbnailmageSize returns a Promise or is an asynchronous function. If it is a synchronous function, you can remove the async keyword and the await statement.)

if my answer makes any problem or make sense to you plz ping me.

Copy link

melvin-bot bot commented Dec 27, 2023

📣 @kevinpetersson! 📣
Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
Please follow these steps:

  1. Make sure you've read and understood the contributing guidelines.
  2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
    Screen Shot 2022-11-16 at 4 42 54 PM
    Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

@kevinpetersson
Copy link

It seems like you are facing an issue where the default size (200, 200) is briefly shown before getting the correct size when using the updateImageSize function. I think the solution is to set an initial state for thumbnailWidth and tumbnailHeight before calculating and updating them. In this way, the
component rendering will have the correct initial values before the asynchronous calculation completes.

Here is my answer.

const updateImageSize = useCallback(
  async ({ width, height }: UpdateImageSizeParams) => {
    // Set initial values to the default size
    let thumbnailWidth = 200;
    let thumbnailHeight = 200;

    // Calculate the thumbnail size asynchronously
    const { thumbnailWidth: calculatedWidth, thumbnailHeight: calculatedHeight } = await calculateThumbnailImageSize(
      width,
      height,
      windowHeight
    );

    // Update the state with the correct size
    thumbnailWidth = calculatedWidth;
    thumbnailHeight = calculatedHeight;

    setCurrentImageWidth(thumbnailWidth);
    setCurrentImageHeight(thumbnailHeight);
  },
  [windowHeight],
);

In this code, by setting the initial values before the asynchronous calculation, you ensure that the default size is set before the component renders. The await keyword is used to wait for the asynchronous calculation to complete before updating the state with the correct size.

(I have assume that calculate ThumbnailmageSize returns a Promise or is an asynchronous function. If it is a synchronous function, you can remove the async keyword and the await statement.)

if my answer makes any problem or make sense to you plz ping me.

@c3024
Copy link
Contributor

c3024 commented Dec 27, 2023

With RNFastImage we had this issue only on Android which was fixed with a patch.

With Expo Image it is on iOS as well.

I think properly addressing the falsy values here

const imageWidth = htmlAttribs['data-expensify-width'] ? parseInt(htmlAttribs['data-expensify-width'], 10) : undefined;
const imageHeight = htmlAttribs['data-expensify-height'] ? parseInt(htmlAttribs['data-expensify-height'], 10) : undefined;

like @mkhutornyi suggested is a good approach.

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Dec 27, 2023
Copy link

melvin-bot bot commented Dec 27, 2023

📣 @mkhutornyi 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job
Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Keep in mind: Code of Conduct | Contributing 📖

@mountiny
Copy link
Contributor

@mkhutornyi can you raise the pr? I think that showing briefly wrong size is fine for now to unblock deploy

Copy link

melvin-bot bot commented Dec 27, 2023

Bug0 Triage Checklist (Main S/O)

  • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
  • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
    • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
  • This bug is reproducible using the reproduction steps in the OP. S/O
    • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
    • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
  • This issue is filled out as thoroughly and clearly as possible
    • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
  • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync

@mountiny
Copy link
Contributor

Fixed in staging
IMG_2104

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Daily KSv2 labels Dec 27, 2023
@melvin-bot melvin-bot bot changed the title [$500] Chat - PDF is not displayed in chat after uploading [HOLD for payment 2024-01-03] [$500] Chat - PDF is not displayed in chat after uploading Dec 27, 2023
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Dec 27, 2023
Copy link

melvin-bot bot commented Dec 27, 2023

Reviewing label has been removed, please complete the "BugZero Checklist".

Copy link

melvin-bot bot commented Dec 27, 2023

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.17-8 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2024-01-03. 🎊

After the hold period is over and BZ checklist items are completed, please complete any of the applicable payments for this issue, and check them off once done.

  • External issue reporter
  • Contributor that fixed the issue
  • Contributor+ that helped on the issue and/or PR

For reference, here are some details about the assignees on this issue:

Copy link

melvin-bot bot commented Dec 27, 2023

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@parasharrajat] The PR that introduced the bug has been identified. Link to the PR:
  • [@parasharrajat] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
  • [@parasharrajat] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:
  • [@parasharrajat] Determine if we should create a regression test for this bug.
  • [@parasharrajat] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
  • [@peterdbarkerUK] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@parasharrajat
Copy link
Member

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@parasharrajat] The PR that introduced the bug has been identified. Link to the PR: Looks like a backend change caused the dimensions to return as 0 which triggered a buggy code from Fix resizes on image upload #8928 causing this issue.
  • [@parasharrajat] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment: https://github.com/Expensify/App/pull/8928/files#r1437162294
  • [@parasharrajat] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion: Not needed
  • [@parasharrajat] Determine if we should create a regression test for this bug. NA. Already exists.
  • [@parasharrajat] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.

@melvin-bot melvin-bot bot added Weekly KSv2 and removed Weekly KSv2 labels Dec 28, 2023
@melvin-bot melvin-bot bot changed the title [HOLD for payment 2024-01-03] [$500] Chat - PDF is not displayed in chat after uploading [HOLD for payment 2024-01-04] [HOLD for payment 2024-01-03] [$500] Chat - PDF is not displayed in chat after uploading Dec 28, 2023
Copy link

melvin-bot bot commented Dec 28, 2023

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.18-8 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2024-01-04. 🎊

After the hold period is over and BZ checklist items are completed, please complete any of the applicable payments for this issue, and check them off once done.

  • External issue reporter
  • Contributor that fixed the issue
  • Contributor+ that helped on the issue and/or PR

For reference, here are some details about the assignees on this issue:

Copy link

melvin-bot bot commented Dec 28, 2023

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@parasharrajat] The PR that introduced the bug has been identified. Link to the PR:
  • [@parasharrajat] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
  • [@parasharrajat] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:
  • [@parasharrajat] Determine if we should create a regression test for this bug.
  • [@parasharrajat] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
  • [@peterdbarkerUK] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@parasharrajat
Copy link
Member

Checklist is posted #33626 (comment)

@melvin-bot melvin-bot bot added Daily KSv2 Overdue and removed Weekly KSv2 labels Jan 2, 2024
Copy link

melvin-bot bot commented Jan 5, 2024

@peterdbarkerUK, @parasharrajat, @mountiny, @mkhutornyi Whoops! This issue is 2 days overdue. Let's get this updated quick!

Copy link

melvin-bot bot commented Jan 9, 2024

@peterdbarkerUK, @parasharrajat, @mountiny, @mkhutornyi Still overdue 6 days?! Let's take care of this!

@peterdbarkerUK
Copy link
Contributor

peterdbarkerUK commented Jan 10, 2024

Payment summary:

@parasharrajat
Copy link
Member

@peterdbarkerUK Feel free to close this. I will request it later.

@parasharrajat
Copy link
Member

Payment requested as per #33626 (comment)

@JmillsExpensify
Copy link

$500 approved for @parasharrajat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 Engineering External Added to denote the issue can be worked on by a contributor
Projects
None yet
Development

No branches or pull requests

9 participants