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

[$250] LHN - Two different chats can be opened at the same time #56947

Open
2 of 8 tasks
lanitochka17 opened this issue Feb 17, 2025 · 23 comments
Open
2 of 8 tasks

[$250] LHN - Two different chats can be opened at the same time #56947

lanitochka17 opened this issue Feb 17, 2025 · 23 comments
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review Weekly KSv2

Comments

@lanitochka17
Copy link

lanitochka17 commented Feb 17, 2025

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.99-0
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught on HybridApp, is this reproducible on New Expensify Standalone?: N
If this was caught during regression testing, add the test name, ID and link from TestRail: N/A
Issue reported by: Applause - Internal Team

Action Performed:

Prerequisite: Account should have at least two different conversations on LHN

  1. Open the Expensify app
  2. Tap on any chat
  3. Before the conversation is displayed, tap on a different chat
  4. When the second chat is opened, tap on the arrow on the top left corner
  5. Check if you land on LHN or on the first opened chat

Expected Result:

Only one conversation should be opened, despite tapping on a different one, before it opens

Actual Result:

Two different chats are opened, when the user taps on any conversation and taps on a different one, before the first one is displayed

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
Bug6745766_1739801510828.Chats.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021895183258683508433
  • Upwork Job ID: 1895183258683508433
  • Last Price Increase: 2025-02-27
  • Automatic offers:
    • huult | Contributor | 106431470
Issue OwnerCurrent Issue Owner: @jayeshmangwani
@lanitochka17 lanitochka17 added Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 labels Feb 17, 2025
Copy link

melvin-bot bot commented Feb 17, 2025

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

@daledah
Copy link
Contributor

daledah commented Feb 18, 2025

🚨 Edited by proposal-police: This proposal was edited at 2025-03-02 03:57:54 UTC.

Proposal

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

Two different chats are opened, when the user taps on any conversation and taps on a different one, before the first one is displayed

What is the root cause of that problem?

In narrow layout, when clicking on any report, we call:

Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(option.reportID));

when the navigation is still in progress, if user clicks on any other report in LHN, it also navigates to that report.

As a result, two chats is opened in stack.

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

We can utilize a debounce function to prevent handling multiple rapid clicks by ignoring subsequent clicks within the debounce period:

const showReportPage = useCallback(

    const showReportPageDebounce = useMemo(() => {
        if (shouldUseNarrowLayout) {
            return debounce(showReportPage, 1000, {leading: true, trailing: false});
        }
        return showReportPage;
    }, [showReportPage, shouldUseNarrowLayout]);

Ensure this debounced function is used at:

onSelectRow={showReportPage}

Can use existed useDebounce instead.

What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

Render the LHN, trigger two consecutive click events in quick succession, and verify that only a single report screen is added to the navigation stack.

What alternative solutions did you explore? (Optional)

We need to implement a mechanism to prevent users from opening more than one report simultaneously.:

    const isNavigatingRef = useRef(false);
    const isFocused = useIsFocused();
    const prevIsFocused = usePrevious(isFocused);
    useEffect(() => {
        if (isFocused && !prevIsFocused && isNavigatingRef.current) {
            isNavigatingRef.current = false;
        }
    }, [isFocused, prevIsFocused]);

Finally, in here add:

            if (isNavigatingRef.current && shouldUseNarrowLayout) {
                return;
            }
           isNavigatingRef.current = true

@Krishna2323
Copy link
Contributor

Krishna2323 commented Feb 18, 2025

Proposal

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

  • LHN - Two different chats can be opened at the same time

What is the root cause of that problem?

  • The onSelectRow row is called without any mechanism to prevent multiple clicks.

onSelectRow={onSelectRow}

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

  • We need to use singleExecution from useSingleExecution hook.
onSelectRow={singleExecution(onSelectRow)}

What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

N/A - Navigation issue

What alternative solutions did you explore? (Optional)

Result

Monosnap.screencast.2025-02-18.17-48-51.mp4

@melvin-bot melvin-bot bot added the Overdue label Feb 20, 2025
Copy link

melvin-bot bot commented Feb 21, 2025

@anmurali Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

Copy link

melvin-bot bot commented Feb 25, 2025

@anmurali 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

@anmurali anmurali removed their assignment Feb 25, 2025
@melvin-bot melvin-bot bot removed the Overdue label Feb 25, 2025
@anmurali anmurali added Overdue Bug Something is broken. Auto assigns a BugZero manager. and removed Bug Something is broken. Auto assigns a BugZero manager. labels Feb 25, 2025
Copy link

melvin-bot bot commented Feb 25, 2025

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

@melvin-bot melvin-bot bot removed the Overdue label Feb 25, 2025
@slafortune slafortune added the External Added to denote the issue can be worked on by a contributor label Feb 27, 2025
@melvin-bot melvin-bot bot changed the title LHN - Two different chats can be opened at the same time [$250] LHN - Two different chats can be opened at the same time Feb 27, 2025
Copy link

melvin-bot bot commented Feb 27, 2025

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

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Feb 27, 2025
Copy link

melvin-bot bot commented Feb 27, 2025

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

@huult
Copy link
Contributor

huult commented Mar 1, 2025

🚨 Edited by proposal-police: This proposal was edited at 2025-03-02 00:46:23 UTC.

Proposal

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

Two different chats can be opened at the same time

What is the root cause of that problem?

Since we selected two reports at the same time and did not implement any prevention, clicking on two reports will execute two navigations

onSelectRow={showReportPage}

Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(option.reportID));

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

To resolve this issue, we should prevent multiple selections and allow only one report to be selected. Additionally, navigation should only occur when the active report is 'Home'.

const showReportPage = useCallback(
(option: Report) => {
// Prevent opening Report page when clicking LHN row quickly after clicking FAB icon
// or when clicking the active LHN row on large screens
// or when continuously clicking different LHNs, only apply to small screen
// since getTopmostReportId always returns on other devices
const reportActionID = Navigation.getTopmostReportActionId();
if ((option.reportID === Navigation.getTopmostReportId() && !reportActionID) || (shouldUseNarrowLayout && isActiveReport(option.reportID) && !reportActionID)) {
return;
}
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(option.reportID));
},
[shouldUseNarrowLayout, isActiveReport],
);

update to:

    const showReportPage = useCallback(
        (option: Report) => {
            // Prevent opening Report page when clicking LHN row quickly after clicking FAB icon
            // or when clicking the active LHN row on large screens
            // or when continuously clicking different LHNs, only apply to small screen
            // since getTopmostReportId always returns on other devices
            const reportActionID = Navigation.getTopmostReportActionId();
            if ((option.reportID === Navigation.getTopmostReportId() && !reportActionID) || (shouldUseNarrowLayout && isActiveReport(option.reportID) && !reportActionID)) {
                return;
            }

             if (Navigation.getActiveRoute() !== '/home' && shouldUseNarrowLayout) { // add this
                return;
            }// add this
                return; // add this
            } // add this
            Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(option.reportID));
        },
        [shouldUseNarrowLayout, isActiveReport],
    );
Screen.Recording.2025-03-02.at.00.06.30.mp4

What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

None

What alternative solutions did you explore? (Optional)

Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

@melvin-bot melvin-bot bot added the Overdue label Mar 2, 2025
@daledah
Copy link
Contributor

daledah commented Mar 2, 2025

Proposal updated

@jayeshmangwani
Copy link
Contributor

@Krishna2323 Have you tested the singleExecution solution on mWeb Safari/Chrome? It doesn’t seem to be working for me on mWeb Safari.

Suggestion: Please always add a reason behind N/A for automated tests.

@melvin-bot melvin-bot bot removed the Overdue label Mar 3, 2025
@jayeshmangwani
Copy link
Contributor

@daledah I don’t entirely agree with using debounce here. I tested the alternative proposal you suggested, but it doesn’t seem to work for me. We can still navigate to two different chats in this case—adding the video below.

navigation-bug-perisist.mov

@daledah
Copy link
Contributor

daledah commented Mar 3, 2025

@jayeshmangwani Sorry, I forgot to include the detailed code changes in my initial proposal. I've now updated my alternative proposal with the necessary details. Can you test it again, thanks?

@daledah
Copy link
Contributor

daledah commented Mar 3, 2025

I don’t entirely agree with using debounce here

I suggested using debounce because it is a common technique for handling rapid, successive event triggers within a short timeframe. By delaying the execution of the event handler until after a specified period of inactivity, debounce helps prevent unnecessary re-renders, redundant API calls, or in this case is the excessive computations that could degrade performance.

@jayeshmangwani
Copy link
Contributor

I suggested using debounce because it is a common technique for handling rapid

Yes, it may be a common technique, but I feel that we should use it only when needed. If we have a better option than setTimeout, that should always be implemented.

@jayeshmangwani
Copy link
Contributor

Can you test it again, thanks?

Yes, I can confirm that it would work.

@jayeshmangwani
Copy link
Contributor

@huult You're suggesting using (Platform.OS === 'ios' || Platform.OS === 'android' || Browser.isMobile()), which is a platform-dependent condition. I think the shouldUseNarrowLayout condition would be more appropriate here

@huult
Copy link
Contributor

huult commented Mar 3, 2025

yes, @jayeshmangwani , I will update the proposal to use shouldUseNarrowLayout. Thanks!

@huult
Copy link
Contributor

huult commented Mar 3, 2025

Proposal updated

  • use shouldUseNarrowLayout

@jayeshmangwani Could you check it again?

@jayeshmangwani
Copy link
Contributor

Thanks for the proposal above! @daledah and @huult's solutions will work here.

But IMO, we can go with @huult's Proposal of checking the current route and returning early if the active route is not home.

🎀 👀 🎀 C+ reviewed

Copy link

melvin-bot bot commented Mar 4, 2025

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

@jayeshmangwani
Copy link
Contributor

@youssef-lr, whenever you get a chance, please check this comment for the selected proposal. Thanks!🙏

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Mar 7, 2025
Copy link

melvin-bot bot commented Mar 7, 2025

📣 @huult 🎉 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 melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Mar 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review Weekly KSv2
Projects
Status: LOW
Development

No branches or pull requests

8 participants