Expensify / App

Welcome to New Expensify: a complete re-imagination of financial collaboration, centered around chat. Help us build the next generation of Expensify by sharing feedback and contributing to the code.
https://new.expensify.com
MIT License
3.56k stars 2.9k forks source link

[HOLD for payment 2024-10-24] [$250] Search - Attachment from qa.guide loads infinitely when opened in Search #50006

Closed lanitochka17 closed 3 weeks ago

lanitochka17 commented 1 month ago

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: 9.0.42-0 Reproducible in staging?: Y Reproducible in production?: Y If this was caught during regression testing, add the test name, ID and link from TestRail: N/A Email or phone of affected tester (no customers): applausetester+kh010901@applause.expensifail.com Issue reported by: Applause - Internal Team

Action Performed:

  1. Go to staging.new.expensify.com
  2. Go to DM
  3. Send the following message. (The message is from qa.guide@team.expensify.com in #admins) Setup Guide GIF
  4. Go to Search > Chat
  5. Click on the message sent in Step 3

Expected Result:

The attachment will load without issue

Actual Result:

The attachment loads infinitely This issue only happens to this specific attachment

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Add any screenshot/video evidence

https://github.com/user-attachments/assets/e01f2bbd-a43a-4abd-a34e-271b8b8ee4f1

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021841561644716083523
  • Upwork Job ID: 1841561644716083523
  • Last Price Increase: 2024-10-02
  • Automatic offers:
    • suneox | Reviewer | 104307339
    • shahinyan11 | Contributor | 104307340
Issue OwnerCurrent Issue Owner: @garrettmknight
melvin-bot[bot] commented 1 month ago

Triggered auto assignment to @garrettmknight (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

lanitochka17 commented 1 month ago

@garrettmknight FYI I haven't added the External label as I wasn't 100% sure about this issue. Please take a look and add the label if you agree it's a bug and can be handled by external contributors

lanitochka17 commented 1 month ago

We think that this bug might be related to #wave-control

melvin-bot[bot] commented 1 month ago

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

melvin-bot[bot] commented 1 month ago

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

huult commented 1 month ago

Edited by proposal-police: This proposal was edited at 2024-10-03 13:17:41 UTC.

Proposal

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

Attachment from qa.guide loads infinitely when opened in Search

What is the root cause of that problem?

The reason for this ticket is that we are attempting to authenticate an attachment that is not an Expensify source, which prevents the attachment from loading and results in an infinite loading state.

In the case of this ticket, this GIF will use AttachmentView, and the isAuthTokenRequired prop will be set to true to render this GIF. AttachmentView is used because when the attachment modal is opened, the URL contains reportID set to -1, which prevents load the report. According to condition check #L542, AttachmentView should be rendered for this case. Additionally, this GIF is opened from Search, where isAuthTokenRequired is true, as indicated by condition #L49. So, this GIF is not an Expensify source and will require authentication, as isAuthTokenRequired is set to true, as I mentioned. Therefore, this GIF can't load.

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

I suggest two options to fix this issue:

Option 1: We should update isAuthTokenRequired in cases where the source is not Expensify when opening the attachment modal from Search

// .src/components/SelectionList/ChatListItem.tsx#L43
-    const attachmentContextValue = {type: CONST.ATTACHMENT_TYPE.SEARCH};
+    const attachmentContextValue = {reportID: item.reportID, type: CONST.ATTACHMENT_TYPE.SEARCH};
// .src/components/AttachmentModal.tsx#L543
+  const [isImageAuthTokenRequired, setImageAuthTokenRequired] = useState(isAuthTokenRequired);

-                  {!shouldShowNotFoundPage &&
-                            (!isEmptyObject(report) && !isReceiptAttachment ? (
+                 {!shouldShowNotFoundPage &&
+                            (!isEmptyObject(report) && !isReceiptAttachment && type !== CONST.ATTACHMENT_TYPE.SEARCH ? (
                                <AttachmentCarousel
                                ....
// .src/components/Attachments/AttachmentView/index.tsx#L238
+    const compareImage = useCallback((attachment: Attachment) => attachment.source === source, [source]);
+    useEffect(() => {
+        if (type !== CONST.ATTACHMENT_TYPE.SEARCH) return;
+        const prReportAction = report?.parentReportActionID && parentReportActions ? parentReportActions[report?.parentReportActionID] : undefined;
+       const newAttachments: Attachment[] = extractAttachments(CONST.ATTACHMENT_TYPE.REPORT, {parentReportAction: prReportAction, reportActions: reportActions ?? undefined});

+       const newIndex = newAttachments.findIndex(compareImage);
+       const attachment = newAttachments.at(newIndex);

+      if (attachment?.isAuthTokenRequired !== undefined) {
+          setImageAuthTokenRequired(attachment?.isAuthTokenRequired);
+      }
+  }, [compareImage, parentReportActions, report?.parentReportActionID, reportActions, type]);

// .src/components/AttachmentModal.tsx#L291
<AttachmentViewImage
    ....
+    isAuthTokenRequired={type === CONST.ATTACHMENT_TYPE.SEARCH ? isImageAuthTokenRequired : isAuthTokenRequired}

Test branch for this option

Option 2: We use AttachmentCarousel when opening the attachment modal from Search to fix this issue because AttachmentCarousel checks isAuthTokenRequired for attachments inside. To use AttachmentCarousel, we need to update the code as shown below:

// .src/components/SelectionList/ChatListItem.tsx#L43
-    const attachmentContextValue = {type: CONST.ATTACHMENT_TYPE.SEARCH};
+    const attachmentContextValue = {reportID: item.reportID, type: CONST.ATTACHMENT_TYPE.SEARCH};
POC https://github.com/user-attachments/assets/4a1d8e35-0880-4917-b572-e5502eb9bf80
suneox commented 1 month ago

We’re still awaiting a proposal on this issue. The RCA and solution provided by @huult proposal are not correct.

shahinyan11 commented 1 month ago

@suneox @lanitochka17 I think the "Action performed:" steps and the provided video are not clear to users who are not familiar with Expensify. How to see #admins chat ? What steps should be done to have this message in somewhere to copy and test

suneox commented 1 month ago

@shahinyan11 At step 3 you have to copy content Send the following message ( ... ) included image

shahinyan11 commented 1 month ago

Edited by proposal-police: This proposal was edited at 2024-10-03 18:12:20 UTC.

Proposal

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

Search - Attachment from qa.guide loads infinitely when opened in Search

What is the root cause of that problem?

Here Is described in which cases the image need to have an authToken to be loaded. But the current case is not one of the described cases and we still add authToken to load the image. It comes from here because we set isAuthTokenRequired based on ATTACHMENT_TYPE constant but I think the isAuthTokenRequired prop should be set based on this value.

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

  1. Add one more isAuthTokenRequired param in attachments route here obj

  2. Add isAttachmentOrReceipt as a last param in here

    const route = ROUTES.ATTACHMENTS?.getRoute(reportID ?? '-1', type, source, accountID, isAttachmentOrReceipt);
  3. Update the isAuthTokenRequired prop value to route.params.isAuthTokenRequired

    What alternative solutions did you explore? (Optional)

shahinyan11 commented 1 month ago

@shahinyan11 At step 3 you have to copy content Send the following message ( ... ) included image

@suneox Thanks for your help.

huult commented 1 month ago

Proposal Updated

@suneox, could you please check again? Thank you.

suneox commented 1 month ago

Thanks for all the proposals. I don’t think this issue is related to CORS blocking, since the images from both the chat and the search load the same resource url, just only the headers being different.

https://github.com/user-attachments/assets/a366626c-ed5f-4f8a-9b30-1c047b5ee101

@shahinyan11 Your solution doesn't work on my side

To resolve this issue, we can read the image from the cache to display it when opening the attachment. To retrieve the image from the cache, we update the parameters in the URL to match those of the previous image load.

@huult Could you please explain why updating the reportID parameter in the URL allows us to get a cached image, even though the image source (attachment?source) from URL does not change?

shahinyan11 commented 1 month ago

@suneox Do you mean that my solution doesn't work at all or it's a workaround?

suneox commented 1 month ago

@suneox Do you mean that my solution doesn't work at all or it's a workaround?

@shahinyan11 Your solution doesn’t work as expected, the image still loads indefinitely

https://github.com/user-attachments/assets/598f84b5-9f89-4a63-aa7d-f9e7a1f0d875

shahinyan11 commented 1 month ago

Proposal

Updated. I have updated the RCA and solution. Could you check please and leave feedback

huult commented 1 month ago

Proposal update

Hi @suneox , could you please check it again? thanks

suneox commented 1 month ago

Thanks for all the updates. I’ll reevaluate them within today.

suneox commented 1 month ago

Although both solutions can resolve the issue but @shahinyan11’s solution is simpler. Instead of always setting isAuthTokenRequired in the attachment search case, we will retrieve the isAuthTokenRequired status from the previous thumbnail so we can proceed with @shahinyan11 solution.

🎀 👀 🎀 C+ reviewed

melvin-bot[bot] commented 1 month ago

Triggered auto assignment to @cead22, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

melvin-bot[bot] commented 1 month ago

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

Offer link Upwork job

melvin-bot[bot] commented 1 month ago

📣 @shahinyan11 🎉 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 📖

melvin-bot[bot] commented 1 month ago

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

melvin-bot[bot] commented 1 month ago

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

If no regressions arise, payment will be issued on 2024-10-24. :confetti_ball:

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

melvin-bot[bot] commented 1 month ago

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:

suneox commented 3 weeks ago

Checklist

garrettmknight commented 3 weeks ago

All paid out!