Skip to content

[HOLD for payment 2024-12-20] [$250] Android - Chat - User lands on previous attachment when sending image and opening preview #52415

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

Closed
2 of 8 tasks
lanitochka17 opened this issue Nov 12, 2024 · 37 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 External Added to denote the issue can be worked on by a contributor

Comments

@lanitochka17
Copy link

lanitochka17 commented Nov 12, 2024

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Version Number: 9.0.60-0
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught on HybridApp, is this reproducible on New Expensify Standalone?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail: https://expensify.testrail.io/index.php?/tests/view/5204055&group_by=cases:section_id&group_order=asc&group_id=292107
Issue reported by: Applause - Internal Team

Action Performed:

  1. Open the Expensify app
  2. Open any chat that contains at least an image or video attachment on it
  3. Tap on the "+" button and select "Add Attachment"
  4. Tap on "Choose File" and select any image to upload
  5. Tap on "Send"
  6. Once redirected to chat, tap quickly on the just sent image
  7. Verify that the user lands on the image preview and that it loads correctly

Expected Result:

Preview of the just sent image should load correctly and the user should remain on it when opened

Actual Result:

When sending an image to a chat that already contains an image or video attachment, and opening the preview quickly when it was just sent, the user lands on a previous attachment and not in the one that was selected

Workaround:

Unknown

Platforms:

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

  • Android: Standalone
  • Android: HybridApp
  • Android: mWeb Chrome
  • iOS: Standalone
  • iOS: HybridApp
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence
Bug6662715_1731428003671.Prev_Attachment.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021856559033364524387
  • Upwork Job ID: 1856559033364524387
  • Last Price Increase: 2024-11-20
  • Automatic offers:
    • nkdengineer | Contributor | 105065079
Issue OwnerCurrent Issue Owner: @greg-schroeder
@lanitochka17 lanitochka17 added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Nov 12, 2024
Copy link

melvin-bot bot commented Nov 12, 2024

Triggered auto assignment to @greg-schroeder (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.

@greg-schroeder greg-schroeder added the External Added to denote the issue can be worked on by a contributor label Nov 13, 2024
@greg-schroeder greg-schroeder moved this to Bugs and Follow Up Issues in #expensify-bugs Nov 13, 2024
@melvin-bot melvin-bot bot changed the title Android - Chat - User lands on previous attachment when sending image and opening preview [$250] Android - Chat - User lands on previous attachment when sending image and opening preview Nov 13, 2024
Copy link

melvin-bot bot commented Nov 13, 2024

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

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Nov 13, 2024
Copy link

melvin-bot bot commented Nov 13, 2024

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

@nkdengineer
Copy link
Contributor

Proposal

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

When sending an image to a chat that already contains an image or video attachment, and opening the preview quickly when it was just sent, the user lands on a previous attachment and not in the one that was selected

What is the root cause of that problem?

When we add an attachment and click to open attachment quickly, the item.souce is changed from the local source to the Expensify source after the API is complete

This causes the key of the item to be changed and then onPageSelected is called unexpectedly with the position is the previous attachment

const extractItemKey = useCallback(
(item: Attachment, index: number) =>
typeof item.source === 'string' || typeof item.source === 'number' ? `source-${item.source}` : `reportActionID-${item.reportActionID}` ?? `index-${index}`,
[],
);

key={extractItemKey(item, index)}

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

Since item.source can be changed, we should return the consistent key as reportActionID-${item.reportActionID} or index-{index}

const extractItemKey = useCallback((item: Attachment, index: number) => `reportActionID-${item.reportActionID}`, []);

or

const extractItemKey = useCallback((item: Attachment, index: number) => `index-{index}`, []);

const extractItemKey = useCallback(
(item: Attachment, index: number) =>
typeof item.source === 'string' || typeof item.source === 'number' ? `source-${item.source}` : `reportActionID-${item.reportActionID}` ?? `index-${index}`,
[],
);

What alternative solutions did you explore? (Optional)

Result

Screen.Recording.2024-11-13.at.14.35.58.mov

@huult
Copy link
Contributor

huult commented Nov 13, 2024

Proposal

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

User lands on previous attachment when sending image and opening preview

What is the root cause of that problem?

We send the attachment and open it immediately, so the source will initially be a local path. After the upload is finished, the source changes to the expensify path. This triggers the list to re-render because we used it for the keyExtractor.

const extractItemKey = useCallback(
(item: Attachment, index: number) =>
typeof item.source === 'string' || typeof item.source === 'number' ? `source-${item.source}` : `reportActionID-${item.reportActionID}` ?? `index-${index}`,
[],
);

After the list re-renders, the activePage is lost and reset once the re-render is complete. As a result, we will see the attachment from the previous ticket

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

We can't change the source used as the key because it's meant to prevent unnecessary re-renders when we have multiple sources with the same path.

To resolve this issue, we should store the activePage before the re-render and restore it after the re-render is complete.

  1. Create two variables: keys to store the keys of the list and activePageBeforeChangedKey to store activePage before re-rendering.
// src/components/Attachments/AttachmentCarousel/index.native.tsx#L31
+    const [keys, setKeys] = useState([]);
+    const [activePageBeforeChangedKey, setActivePageBeforeChangedKey] = useState();
  1. Add this block to handle storing the activePage. This only happens if the attachment source is a local file, so we need to check if it is local and key changes.
// src/components/Attachments/AttachmentCarousel/index.native.tsx#L111
+    const extractItemKey = useCallback((item: Attachment, index: number) => {
+        return typeof item.source === 'string' || typeof item.source === 'number' ? `source-${item.source}` : `reportActionID-${item.reportActionID}` ?? `index-${index}`;
+    }, []);

+    useEffect(() => {
+        const currentKeys = attachments.map((item, index) => extractItemKey(item, index));
+        const isIncludedLocalFile = attachments.some((item) => FileUtils.isLocalFile(item.source));

+        if (JSON.stringify(currentKeys) !== JSON.stringify(keys) && isIncludedLocalFile) {
+            console.log('Keys have changed');
+            setKeys(currentKeys);
+            setActivePageBeforeChangedKey(page);
+        }
+    }, [activePageBeforeChangedKey, attachments, extractItemKey, keys, page]);
  1. After the page re-renders, restore the key and reset activePageBeforeChangedKey
+    useEffect(() => {
+        if (page === activePageBeforeChangedKey || activePageBeforeChangedKey === undefined) {
+            return;
+        }

+        setPage(activePageBeforeChangedKey);
+        if (activePageBeforeChangedKey) {
+            pagerRef.current?.setPage(activePageBeforeChangedKey);
+        }
+        setActivePageBeforeChangedKey(undefined);
+    }, [activePageBeforeChangedKey, page]);

Note: We can still apply this logic if the web platform is also affected

Test branch

POC
Screen.Recording.2024-11-14.at.00.36.13.mp4

@greg-schroeder
Copy link
Contributor

Proposal review next up!

@akinwale
Copy link
Contributor

We can move forward with @nkdengineer's proposal here.

🎀👀🎀 C+ reviewed.

Copy link

melvin-bot bot commented Nov 14, 2024

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

@huult
Copy link
Contributor

huult commented Nov 14, 2024

@akinwale Can you take a look at my proposal? If we don't use source as the key, then in case of the same source, it will re-render.

Copy link

melvin-bot bot commented Nov 19, 2024

@akinwale, @greg-schroeder, @srikarparsi Huh... This is 4 days overdue. Who can take care of this?

@melvin-bot melvin-bot bot added the Overdue label Nov 19, 2024
@srikarparsi
Copy link
Contributor

Hey @akinwale, have you had a chance to look at @huult's comment?

@akinwale
Copy link
Contributor

@akinwale Can you take a look at my proposal? If we don't use source as the key, then in case of the same source, it will re-render.

@huult Could you post a video showing this re-render behaviour? I can't seem to reproduce on my end.

@melvin-bot melvin-bot bot removed the Overdue label Nov 20, 2024
@nkdengineer
Copy link
Contributor

If we don't use source as the key, then in case of the same source, it will re-render.

The source can not be the same and using a stable key doesn't cause any problem.

Copy link

melvin-bot bot commented Nov 20, 2024

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

@huult
Copy link
Contributor

huult commented Nov 21, 2024

@akinwale I tested the case test and pasted it twice. This is a case with the same source, but I saw that it is handled elsewhere. So, I think my comment is outdated. Thanks.

@nkdengineer
Copy link
Contributor

@srikarparsi We have no concerns now. We're good to move this forward.

Copy link

melvin-bot bot commented Nov 25, 2024

@akinwale, @greg-schroeder, @srikarparsi Eep! 4 days overdue now. Issues have feelings too...

@melvin-bot melvin-bot bot added the Overdue label Nov 25, 2024
@melvin-bot melvin-bot bot added Weekly KSv2 and removed Daily KSv2 labels Nov 26, 2024
@mvtglobally
Copy link

Issue not reproducible during KI retests. (First week)

@greg-schroeder
Copy link
Contributor

PR in review, comments as of 6 hours ago

@greg-schroeder
Copy link
Contributor

greg-schroeder commented Dec 9, 2024

Work on linked PR continues

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Dec 13, 2024
@melvin-bot melvin-bot bot changed the title [$250] Android - Chat - User lands on previous attachment when sending image and opening preview [HOLD for payment 2024-12-20] [$250] Android - Chat - User lands on previous attachment when sending image and opening preview Dec 13, 2024
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Dec 13, 2024
Copy link

melvin-bot bot commented Dec 13, 2024

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

Copy link

melvin-bot bot commented Dec 13, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 9.0.75-6 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-12-20. 🎊

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

Copy link

melvin-bot bot commented Dec 13, 2024

@akinwale @greg-schroeder @akinwale The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

@greg-schroeder
Copy link
Contributor

@akinwale just needs to work through the checklist and then we'll be good to go for 12/20!

@garrettmknight garrettmknight moved this from Bugs and Follow Up Issues to Hold for Payment in #expensify-bugs Dec 17, 2024
@akinwale
Copy link
Contributor

BugZero Checklist:

  • [Contributor] Classify the bug:
Bug classification

Source of bug:

  • 1a. Result of the original design (eg. a case wasn't considered)
  • 1b. Mistake during implementation
  • 1c. Backend bug
  • 1z. Other:

Where bug was reported:

  • 2a. Reported on production (eg. bug slipped through the normal regression and PR testing process on staging)
  • 2b. Reported on staging (eg. found during regression or PR testing)
  • 2d. Reported on a PR
  • 2z. Other:

Who reported the bug:

  • 3a. Expensify user
  • 3b. Expensify employee
  • 3c. Contributor
  • 3d. QA
  • 3z. Other:
  • [Contributor] 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: N/A

  • [Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source 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: N/A

  • [Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.

  • [BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.

    Link to issue:

Regression Test Proposal

Test:

  1. Launch the Expensify app
  2. Open a chat report that contains at least two attachments (image or video)
  3. Click on the "+" icon and select Add Attachment
  4. Select Choose File and select any image to upload
  5. Click on Send
  6. After being redirected to the chat report, tap quickly on the image that was just uploaded
  7. Verify that the preview of the image that was just uploaded should load correctly and the user should remain on the image when opened

Do we agree 👍 or 👎?

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

melvin-bot bot commented Dec 23, 2024

@akinwale, @greg-schroeder, @srikarparsi, @nkdengineer Whoops! This issue is 2 days overdue. Let's get this updated quick!

@JmillsExpensify
Copy link

Waiting on summary to approve New Expensify payment.

Copy link

melvin-bot bot commented Dec 25, 2024

@akinwale, @greg-schroeder, @srikarparsi, @nkdengineer Eep! 4 days overdue now. Issues have feelings too...

Copy link

melvin-bot bot commented Dec 27, 2024

@akinwale, @greg-schroeder, @srikarparsi, @nkdengineer 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

Copy link

melvin-bot bot commented Dec 31, 2024

@akinwale, @greg-schroeder, @srikarparsi, @nkdengineer 10 days overdue. I'm getting more depressed than Marvin.

@greg-schroeder
Copy link
Contributor

Apologies for the delay on this over the holiday. Processing

@melvin-bot melvin-bot bot removed the Overdue label Dec 31, 2024
@greg-schroeder
Copy link
Contributor

Payment summary:

Contributor: @nkdengineer - $250 - Upwork
C+: @akinwale - $250 - Can be paid via ND manual request

Regression test filed.

Good to go @JmillsExpensify

@github-project-automation github-project-automation bot moved this from Hold for Payment to Done in #expensify-bugs Dec 31, 2024
@JmillsExpensify
Copy link

$250 approved for @akinwale

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 External Added to denote the issue can be worked on by a contributor
Projects
Status: Done
Development

No branches or pull requests

8 participants