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 2023-11-09] [$1000] Web - API OpenReport shows after switch away from the app and back #27887

Closed
1 of 6 tasks
kbecciv opened this issue Sep 20, 2023 · 67 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 Sep 20, 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!


Action Performed:

  1. Log in with any account
  2. Open Developer tool - Network
  3. Switch away from the app and back

Expected Result:

NO api OpenReport shows after switch away and back

Actual Result:

API OpenReport shows after switch away and back

Workaround:

Unknown

Platforms:

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

  • Android / native
  • Android / Chrome
  • iOS / native
  • iOS / Safari
  • MacOS / Chrome / Safari
  • MacOS / Desktop

Version Number: 1.3.72.6
Reproducible in staging?: y
Reproducible in production?: y
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
Notes/Photos/Videos: Any additional supporting documentation

image (49)

Recording.4659.mp4

Expensify/Expensify Issue URL:
Issue reported by: @quinthar
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1695079219960739

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~014f1c0d7d7d757660
  • Upwork Job ID: 1704588615900069888
  • Last Price Increase: 2023-10-11
  • Automatic offers:
    • hoangzinh | Reviewer | 27362270
    • saranshbalyan-1234 | Contributor | 27362271
@kbecciv kbecciv added External Added to denote the issue can be worked on by a contributor Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Sep 20, 2023
@melvin-bot melvin-bot bot changed the title Web - API OpenReport shows after switch away from the app and back [$500] Web - API OpenReport shows after switch away from the app and back Sep 20, 2023
@melvin-bot
Copy link

melvin-bot bot commented Sep 20, 2023

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

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Sep 20, 2023
@melvin-bot
Copy link

melvin-bot bot commented Sep 20, 2023

Triggered auto assignment to @garrettmknight (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@melvin-bot
Copy link

melvin-bot bot commented Sep 20, 2023

Triggered auto assignment to @laurenreidexpensify (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.

@melvin-bot
Copy link

melvin-bot bot commented Sep 20, 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

@melvin-bot
Copy link

melvin-bot bot commented Sep 20, 2023

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

@saranshbalyan-1234
Copy link
Contributor

saranshbalyan-1234 commented Sep 20, 2023

Proposal

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

OpenReport API gets called after switching tabs

What is the root cause of that problem?

We are calling the OpenReport API if visibility changes.

useFocusEffect(
useCallback(() => {
const unsubscribeVisibilityListener = Visibility.onVisibilityChange(() => {
const isTopMostReportID = Navigation.getTopmostReportId() === getReportID(route);
// If the report is not fully visible (AKA on small screen devices and LHR is open) or the report is optimistic (AKA not yet created)
// we don't need to call openReport
if (!getIsReportFullyVisible(isTopMostReportID) || report.isOptimisticReport) {
return;
}
Report.openReport(report.reportID);
});
return () => unsubscribeVisibilityListener();
// The effect should run only on the first focus to attach listener
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []),
);

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

Based upon the suggestions as per this comment
#27887 (comment)
#27887 (comment)
We are going to remove this code.

Just need to either remove or comment the above code and its working fine.

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

N/A

@abdel-h66
Copy link
Contributor

abdel-h66 commented Sep 20, 2023

Proposal

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

OpenReport is called even when the report is already focused.

What is the root cause of that problem?

We are using the useFocusEffect to handle opening a report but this will run every time the repors gets back to view

useFocusEffect(
useCallback(() => {
const unsubscribeVisibilityListener = Visibility.onVisibilityChange(() => {
const isTopMostReportID = Navigation.getTopmostReportId() === getReportID(route);
// If the report is not fully visible (AKA on small screen devices and LHR is open) or the report is optimistic (AKA not yet created)
// we don't need to call openReport
if (!getIsReportFullyVisible(isTopMostReportID) || report.isOptimisticReport) {
return;
}
Report.openReport(report.reportID);
});
return () => unsubscribeVisibilityListener();
// The effect should run only on the first focus to attach listener
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []),
);

And I think the Report.openReport(report.reportID); called inside the useFocusEffect is a duplicate to fetchReportIfNeeded()

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

I would suggest removing the call Report.openReport(report.reportID);

    useFocusEffect(
        useCallback(() => {
            const unsubscribeVisibilityListener = Visibility.onVisibilityChange(() => {
                const isTopMostReportID = Navigation.getTopmostReportId() === getReportID(route);
                // If the report is not fully visible (AKA on small screen devices and LHR is open) or the report is optimistic (AKA not yet created)
                // we don't need to call openReport
                if (!getIsReportFullyVisible(isTopMostReportID) || report.isOptimisticReport) {
                    return;
                }

              // Remove this call. 
                Report.openReport(report.reportID);
            });

            return () => unsubscribeVisibilityListener();
        }, []),
    );

What alternative solutions did you explore? (Optional)

N/A

@hoangzinh
Copy link
Contributor

Thank you @saranshbalyan-1234 and @abdel-h66 for your proposals.

Both proposals correctly pointed out the LOC that will trigger the OpenReport API command when users switch tabs. But we haven't pointed out the reason why we have those LOCs in the beginning. Without clearing the reason, it will be easy to revert the fix for a bug/requirement that we would like to cover before. Could you please investigate deeper on that? Thanks

@laurenreidexpensify laurenreidexpensify removed their assignment Sep 21, 2023
@abdel-h66
Copy link
Contributor

Yes that's true @hoangzinh after digging deeper into the previous changes for that part of the code, I found a PR that fixed the following issue.

Switching other app after receiving messages, message will be marked 'read'
#15634

This means that the visibility change subscription serves as a guard against reading messages without actually seeing them so removing it will definitly break this.

As this being said, the issue seemed to appear on mobile only because that's where the getIsReportFullyVisible will return false, with the LHN open.

So that check fixes the report being opened without seeing it, but that doesn't stop the call on devices where the report is already open and visibitly changes.

I found out that adding a third check isTopMostReportID, while keeping the previous one to guard againt a regression will stop the unecessary call to OpenReport on an already open report. The solution. will look something like this.

    useFocusEffect(
        useCallback(() => {
            const unsubscribeVisibilityListener = Visibility.onVisibilityChange(() => {
                const isTopMostReportID = Navigation.getTopmostReportId() === getReportID(route);
                // If the report is not fully visible (AKA on small screen devices and LHR is open) or the report is optimistic (AKA not yet created)
                // we don't need to call openReport
                if (!getIsReportFullyVisible(isTopMostReportID) || report.isOptimisticReport) {
                    return;
                }

                if(isTopMostReportID) {
                    return;
                }


                Report.openReport(report.reportID);
            });

            return () => unsubscribeVisibilityListener();
            // The effect should run only on the first focus to attach listener
            // eslint-disable-next-line react-hooks/exhaustive-deps
        }, []),
    );

@saranshbalyan-1234
Copy link
Contributor

@hoangzinh the isuue is with the useLayoutEffect which is causing api to be called whenever screen is focused,

useFocusEffect(
useCallback(() => {
const unsubscribeVisibilityListener = Visibility.onVisibilityChange(() => {
const isTopMostReportID = Navigation.getTopmostReportId() === getReportID(route);
// If the report is not fully visible (AKA on small screen devices and LHR is open) or the report is optimistic (AKA not yet created)
// we don't need to call openReport
if (!getIsReportFullyVisible(isTopMostReportID) || report.isOptimisticReport) {
return;
}
Report.openReport(report.reportID);
});
return () => unsubscribeVisibilityListener();
// The effect should run only on the first focus to attach listener
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []),
);

Instead useLayoutEffect we can keep this code in a useEffect which is solving the issue, tested and its working fine with useEffect

@saranshbalyan-1234
Copy link
Contributor

moreover @abdel-h66 's proposed solution is not working

   if(isTopMostReportID) {
                    return;
                }

Thinking moving it to useEffect would make much sense

@abdel-h66
Copy link
Contributor

I just double checked my solution @saranshbalyan-1234 and it seems working just fine 😅 do you have a specific use case where it didn't work I would like to check

@hoangzinh
Copy link
Contributor

hoangzinh commented Sep 22, 2023

@abdel-h66, I don't think it's related to the issue #15634. This issue solved another problem on small screen devices, where the user is still on LHN but the App still marks unread messages as read (just in case you don't know what LHN stands for, please take a look at this doc https://github.com/Expensify/App/blob/main/contributingGuides/CONTRIBUTING.md#guide-on-acronyms-used-within-expensify-communication)

So by introducing the third check as you mentioned

I found out that adding a third check isTopMostReportID,

AFAIK, the below code will never be called. Because in Web, we always open a report => isTopMostReportID always has value, so it's the same as we remove the App visible callback as described in your proposal.

I just checked, your third check of isTopMostReportID is a conjunction of 2nd check here so the below code will never be called

@hoangzinh
Copy link
Contributor

@saranshbalyan-1234 I don't think it's related to useLayoutEffect hook, because this hook is only used to register the App visible callback Visibility.onVisibilityChange when the Report screen is focused back. Moreover, I tried to test your suggestion but it still calls OpenReport API when switching tabs

@saranshbalyan-1234
Copy link
Contributor

after removing cache, my proposal did not work, my bad!

@melvin-bot melvin-bot bot added the Overdue label Sep 25, 2023
@melvin-bot
Copy link

melvin-bot bot commented Sep 25, 2023

@garrettmknight, @hoangzinh Whoops! This issue is 2 days overdue. Let's get this updated quick!

@garrettmknight
Copy link
Contributor

@abdel-h66 can you update your solution with @hoangzinh's feedback?

@melvin-bot melvin-bot bot removed the Overdue label Sep 25, 2023
@abdel-h66
Copy link
Contributor

Yes @garrettmknight I still didnt have time for a second look on this one, I will update here once I try something different

@saranshbalyan-1234
Copy link
Contributor

@marcaaron sure will update it soon, Thank you for the offer

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Oct 25, 2023
@saranshbalyan-1234
Copy link
Contributor

PR raised, please check @hoangzinh @marcaaron

@saranshbalyan-1234
Copy link
Contributor

creating a new PR due to conflicts, sorry for inconvienience

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Oct 30, 2023
@melvin-bot melvin-bot bot changed the title [$1000] Web - API OpenReport shows after switch away from the app and back [HOLD for payment 2023-11-09] [$1000] Web - API OpenReport shows after switch away from the app and back Nov 2, 2023
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Nov 2, 2023
Copy link

melvin-bot bot commented Nov 2, 2023

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

Copy link

melvin-bot bot commented Nov 2, 2023

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.3.94-2 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 2023-11-09. 🎊

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 Nov 2, 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:

  • [@hoangzinh] The PR that introduced the bug has been identified. Link to the PR:
  • [@hoangzinh] 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:
  • [@hoangzinh] 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:
  • [@hoangzinh] Determine if we should create a regression test for this bug.
  • [@hoangzinh] 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.
  • [@garrettmknight] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@melvin-bot melvin-bot bot added Daily KSv2 Overdue and removed Weekly KSv2 labels Nov 8, 2023
@garrettmknight
Copy link
Contributor

Summarizing payments:

@hoangzinh can you get to the checklist when you get a chance

@melvin-bot melvin-bot bot removed the Overdue label Nov 10, 2023
@hoangzinh
Copy link
Contributor

BugZero Checklist:

  • The PR that introduced the bug has been identified. Link to the PR: Refactor Update Last Read #9529
  • 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: 🚫 According to the comment here [HOLD for payment 2023-11-09] [$1000] Web - API OpenReport shows after switch away from the app and back #27887 (comment), I think it's not a regression bug, but it's about design purpose at this time.
  • 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: N/A
  • Determine if we should create a regression test for this bug ⛔ Nope, it's just a perf improvement, removing a redundant API call when switching the browser tab.

@melvin-bot melvin-bot bot added the Overdue label Nov 13, 2023
@garrettmknight
Copy link
Contributor

Nice one, closing!

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
Development

No branches or pull requests

9 participants