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

Fix double click navigating twice on lists #25604

Merged

Conversation

huzaifa-99
Copy link
Contributor

@huzaifa-99 huzaifa-99 commented Aug 21, 2023

Details

The onSelectRow of <SelectionList/> was running multiple times on multiple quick clicks/presses. This caused some side-effects like navigation and API calls that ran in some of the callbacks for the onSelectRow prop to also run multiple times.

This PR adds a debounce time prop debouncedOnRowSelect for the onSelectRow in <SelectionList/> to prevent unnecessary function calls to onSelectRow from happening.

Fixed Issues

$ #24074
PROPOSAL: #24074 (comment)

Tests

Visit each of these components/pages and verify that pressing any option from the list multiple times (either with a mouse click, touch, arrow keys + enter) doesn’t navigate to or navigate back multiple times or make multiple API calls.

  1. SearchPage -> /search
  2. PronounsPage -> /settings/profile/pronouns
  3. TimezoneSelectPage -> /settings/profile/timezone/select
  4. CountrySelectionPage -> /settings/profile/address/country
  5. PriorityModePage -> /settings/preferences/priority-mode
  6. LanguagePage -> /settings/preferences/language
  7. ThemePage -> /settings/preferences/theme
  8. NotificationPreferencePage -> /w/{workspaceID}/r/{reportID}/settings/notification-preferences
  9. WriteCapabilityPage -> /w/{workspaceID}/r/{reportID}/settings/who-can-post
  10. VisibilityPage -> /w/{workspaceID}/r/{reportID}/settings/visibility
  11. TaskAssigneeSelectorModal -> /r/{reportID}/assignee
  12. TaskShareDestinationSelectorModal -> /new/task/share-destination
  13. IOUCurrencySelection -> create/send/currency/1/{requestID}
  14. MoneyRequestParticipantsSelector -> /create/send/participants/1/{requestID}
  15. IOURequestStepCurrency -> /create/request/currency/1/{requestID}
  16. MoneyTemporaryForRefactorRequestParticipantsSelector -> /create/request/participants/1/{requestID}
  17. WorkspaceProfileCurrencyPage -> /workspace/{workspaceID}/profile/currency
  18. WorkspaceUnitPage -> /workspace/{workspaceID}/rateandunit/unit
  19. WorkspaceAutoReportingMonthlyOffsetPage -> /workspace/{workspaceID}/settings/workflows/auto-reporting-frequency/monthly-offset
  20. BusinessTypeSelectorModal -> /bank-account/ — visit company step incorporation type
  21. WorkspaceMemberDetailsRoleSelectionPage -> /settings/workspaces/{workspaceID}/members/{accountID}/role-selection
  22. WorkspaceWorkflowsApproverPage -> /settings/workspaces/{workspaceID}/settings/workflows/approver
  23. WorkspaceWorkflowsPayerPage -> /workspace/{workspaceID}/settings/workflows/payer
  • Verify that no errors appear in the JS console

Offline tests

Same as "Tests" section above

QA Steps

Same as "Tests" section above

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • If we are not using the full Onyx data that we loaded, I've added the proper selector in order to ensure the component only re-renders when the data it is using changes
      • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web

Chrome

Web.Chrome.1.mp4
Web.Chrome.2.mp4

Safari

Web.Safari.1.mp4
Web.Safari.2.mp4
Mobile Web - Chrome
mWeb.Chrome.1.mp4
mWeb.Chrome.2.mp4
mWeb.Chrome.3.mp4
Mobile Web - Safari
mWeb.Safari.1.mp4
mWeb.Safari.2.mp4
Desktop
Desktop.Native.1.mp4
Desktop.Native.2.mp4
iOS
IOS.Native.1.mp4
IOS.Native.2.mp4
Android
Android.Native.1.mp4
Android.Native.2.mp4
Android.Native.3.mp4

@huzaifa-99 huzaifa-99 requested a review from a team as a code owner August 21, 2023 17:38
@melvin-bot melvin-bot bot requested review from parasharrajat and removed request for a team August 21, 2023 17:38
@melvin-bot
Copy link

melvin-bot bot commented Aug 21, 2023

@parasharrajat Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

Copy link
Member

@parasharrajat parasharrajat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix Lint warnings..

src/components/OptionRow.js Outdated Show resolved Hide resolved
src/components/OptionRow.js Outdated Show resolved Hide resolved
src/components/MoneyRequestConfirmationList.js Outdated Show resolved Hide resolved
@huzaifa-99
Copy link
Contributor Author

@parasharrajat Thank you for the quick response.

I have replied to your feedback above. Please have a look when you get a change.

@huzaifa-99
Copy link
Contributor Author

Gentle bump @parasharrajat. Also, I replied to your comments above.

@huzaifa-99
Copy link
Contributor Author

Bump @parasharrajat.

@parasharrajat
Copy link
Member

Checking it.

@parasharrajat
Copy link
Member

Oops, the backend is throwing errors ATM and not letting me in. I will check back in sometime.

@huzaifa-99
Copy link
Contributor Author

huzaifa-99 commented Aug 23, 2023

Sure no worries. I thought it was just me :)

@huzaifa-99
Copy link
Contributor Author

huzaifa-99 commented Aug 24, 2023

Bump @parasharrajat, the BE seems to be fixed now. Please have a look when you get a chance. Thanks

@parasharrajat
Copy link
Member

@huzaifa-99 Please merge main.

@huzaifa-99
Copy link
Contributor Author

Main merged @parasharrajat.

src/components/OptionRow.js Outdated Show resolved Hide resolved
src/components/OptionRow.js Outdated Show resolved Hide resolved
src/components/OptionRow.js Outdated Show resolved Hide resolved
src/components/OptionsList/BaseOptionsList.js Outdated Show resolved Hide resolved
src/components/SelectionList/BaseSelectionList.js Outdated Show resolved Hide resolved
src/components/SelectionList/BaseSelectionList.js Outdated Show resolved Hide resolved
src/pages/settings/Profile/PronounsPage.js Outdated Show resolved Hide resolved
src/components/SelectionList/selectionListPropTypes.js Outdated Show resolved Hide resolved
src/components/SelectionList/BaseSelectionList.js Outdated Show resolved Hide resolved
mountiny
mountiny previously approved these changes May 23, 2024
Copy link
Contributor

@mountiny mountiny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but got one question

src/components/MenuItemList.tsx Outdated Show resolved Hide resolved
src/components/SelectionList/BaseSelectionList.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@mountiny mountiny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@mountiny mountiny merged commit 2a7d5d4 into Expensify:main May 28, 2024
17 checks passed
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 1.4.77-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@kbecciv
Copy link

kbecciv commented May 30, 2024

This PR is failing because of issue #24074

The issue is reproducible in: Web, mWeb and Desktop

1717063381253.1.mp4
1717059402328.Wkgn6986.mp4

@parasharrajat
Copy link
Member

@kbecciv Could you please mention where it is failing?

@kbecciv
Copy link

kbecciv commented May 30, 2024

On mWeb - double tapping any option in Priority mode, Language or Theme in the Preferences menu takes the user back to the Account settings.

CVDN6051.MP4

On Web - changing the approver with a double click returns the user to the workspace settings for the first try.
Preferences menu double clicks are also navigating the user back to the previous page.

bandicam.2024-05-30.12-20-53-216.mp4

On Desktop - after few clicking on the list item the app jump from the Preferences to the Profile tab.

Screen.Recording.2024-05-30.at.18.04.49.1.mp4

@parasharrajat
Copy link
Member

parasharrajat commented May 30, 2024

Looks like we didn't clearly specify the test steps. @huzaifa-99 Could you please update those to be more clear?

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/puneetlath in version: 1.4.77-11 🚀

platform result
🤖 android 🤖 failure ❌
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/puneetlath in version: 1.4.77-11 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@parasharrajat
Copy link
Member

@huzaifa-99 Did you look into the comments from QA team?

@huzaifa-99
Copy link
Contributor Author

@parasharrajat my apologies for the issue here. I just had a look and it is reproducible with mouse/touch clicks and works correctly with the enter keys for focused options.

We are using this debounce timer in BaseSelectionList for mouse/touch clicks, trying to run it on the leading edge which is proving insufficient for some pages.

const debouncedOnSelectRow = useCallback(lodashDebounce(onSelectRow, 1000, {leading: true}), [onSelectRow]);

I tested with a 200ms delay on the trailing edge when shouldDebounceRowSelect: true

const debouncedOnSelectRow = useCallback(lodashDebounce(onSelectRow, 200), [onSelectRow]);

this seems to do the trick, but again this is on the trailing edge. We can also throw in a maxWait: 200 to run the callback once in that interval (the recording below doesn't include maxWait option)

recording.mp4

What direction should we follow, @parasharrajat?

@parasharrajat
Copy link
Member

Could you please share explanation of the problem? Also explain impact of each suggestion and how it is different from old solution?

@huzaifa-99
Copy link
Contributor Author

Backstory
  • In some cases, the callback provided to the onSelectRow prop of <BaseSelectionList/> triggers a navigation action.
  • For mouse/touch clicks only, we debounce the onSelectRow prop on the leading edge.

In some scenarios, the onSelectRow prop changes after execution but before navigation. This change cancels any existing debouncedOnSelectRow, creating a new debouncedOnSelectRow. The second click callback then executes the newer debouncedOnSelectRow function on the leading edge, causing unnecessary navigation.

In terms of events, it would be like this

  1. User clicks an option
  2. debouncedOnSelectRow executes on leading-edge
  3. onSelectRow prop changes, canceling any existing debouncedOnSelectRow and making a new debouncedOnSelectRow
  4. The 2nd click callback uses the newer debouncedOnSelectRow, this causes the 2nd unnecessary navigation

You can test this out by making the onSelectRow prop to not change debouncedOnSelectRow (just for testing).

- const debouncedOnSelectRow = useCallback(lodashDebounce(onSelectRow, 1000, {leading: true}), [onSelectRow]);
+ const debouncedOnSelectRow = useCallback(lodashDebounce(onSelectRow, 1000, {leading: true}), [
+     // onSelectRow
+ ]);

The original assumption was for onSelectRow to change after execution but after all of its navigation calls are completed, by which time the current component would be unmounted, and no more extra navigations would happen. But the navigation calls take time and onSelectRow updates before navigating to a different page, which causes event 3.

If we debounce on the trailing edge, it won't give enough time for event 4 to happen, the navigation calls would have finished by then. The same solution, but with some delay timer on the trailing edge, rather than the leading one. I experimented with this and it seems to work for click/touch events for navigation cases

- const debouncedOnSelectRow = useCallback(lodashDebounce(onSelectRow, 1000, {leading: true}), [onSelectRow]);
+ const debouncedOnSelectRow = useCallback(lodashDebounce(onSelectRow, 200), [onSelectRow]);

I tested it out and it looks like the recording from this comment.

This is only for the mouse/touch clicks, the arrow keys debounce works correctly in current state.

cc: @parasharrajat

@huzaifa-99
Copy link
Contributor Author

Bump, @parasharrajat

@mountiny
Copy link
Contributor

@parasharrajat can you please check that out?

@parasharrajat
Copy link
Member

parasharrajat commented Jun 21, 2024

@huzaifa-99 Ok, I see. Let's do that. Please open a new PR. I don't see any other solution.

@huzaifa-99
Copy link
Contributor Author

@huzaifa-99 Ok, I see. Let's do that. Please open a new PR. I don't see any other solution.

sure, will try to create one by EOD tomorrow.

@huzaifa-99
Copy link
Contributor Author

PR created: #44360, apologies for the delay.

cc: @parasharrajat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants