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-06-01] [HOLD for payment 2023-05-23] [$2000] Fast clicking any button 'n' times execute 'n' times #14572

Closed
1 task
kavimuru opened this issue Jan 25, 2023 · 191 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2

Comments

@kavimuru
Copy link

kavimuru commented Jan 25, 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!


HOLD on #17404

Action Performed:

  1. Click on settings and go to workspaces
  2. Fast Click the new workspace button ‘n’ times. Let’s say triple-click the button

Expected Result:

  1. Not to be able to fast click any button, after the first click the button should be disabled or have no effect until the initial click effects are done. i.e. Clicking ‘New Workspace’ button multiple times should just create a single workspace.

Note: The issue is reproducible with all buttons e.g. the IOU's I'll settle up elsewhere button as reported on #17167.

Actual Result:

Clicking ‘New workspace’ button ‘n’ number of times creates ‘n’ number of workspaces

If you follow the same step from 1-4 on web or mweb , then clicking the new workspace button ‘n’ number of times just creates a single workspace and not ‘n’ number of workspaces

Workaround:

unknown

Platforms:

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

  • Android / native

Version Number: 1.2.59-1
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:

az_recorder_20230125_172005.1.mp4
workspace.1.mp4

Expensify/Expensify Issue URL:
Issue reported by: @priya-zha
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1674643973375769

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01a7c5579c82436a8d
  • Upwork Job ID: 1619020532492161024
  • Last Price Increase: 2023-04-25
@kavimuru kavimuru added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Jan 25, 2023
@melvin-bot melvin-bot bot locked and limited conversation to collaborators Jan 25, 2023
@slafortune slafortune added the External Added to denote the issue can be worked on by a contributor label Jan 27, 2023
@melvin-bot melvin-bot bot unlocked this conversation Jan 27, 2023
@melvin-bot melvin-bot bot changed the title Clicking New workspace button ‘n’ number of times creates ‘n’ number of workspaces immediately [$1000] Clicking New workspace button ‘n’ number of times creates ‘n’ number of workspaces immediately Jan 27, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jan 27, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Jan 27, 2023

Current assignee @slafortune is eligible for the External assigner, not assigning anyone new.

@melvin-bot
Copy link

melvin-bot bot commented Jan 27, 2023

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

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

melvin-bot bot commented Jan 27, 2023

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

@esh-g
Copy link
Contributor

esh-g commented Jan 27, 2023

Proposal

Solution

We can add a callback function to the createWorkspace method that disables the button and enables it only after the workspace is successfully created. This can be wither implemented via a callback method or promise

Option 1: (callback)

diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js
index c269accf6..de927f481 100644
--- a/src/libs/actions/Policy.js
+++ b/src/libs/actions/Policy.js
@@ -940,6 +940,7 @@ function createWorkspace(ownerEmail = '', makeMeAdmin = false, policyName = '',
                 Navigation.dismissModal(); // Dismiss /transition route for OldDot to NewDot transitions
             }
             Navigation.navigate(ROUTES.getWorkspaceInitialRoute(policyID));
+            callback();
         });
 }
 
diff --git a/src/pages/workspace/WorkspacesListPage.js b/src/pages/workspace/WorkspacesListPage.js
index 5ef22eea7..d394a3240 100755
--- a/src/pages/workspace/WorkspacesListPage.js
+++ b/src/pages/workspace/WorkspacesListPage.js
@@ -93,9 +93,16 @@ class WorkspacesListPage extends Component {
     constructor(props) {
         super(props);
 
+        this.state = {
+            isDisabled: false,
+        }
+
+
         this.getWalletBalance = this.getWalletBalance.bind(this);
         this.getWorkspaces = this.getWorkspaces.bind(this);
         this.getMenuItem = this.getMenuItem.bind(this);
+        this.createNewWorkspace = this.createNewWorkspace.bind(this);
+
     }
 
     /**
@@ -171,6 +178,11 @@ class WorkspacesListPage extends Component {
         );
     }
 
+    createNewWorkspace() {
+        this.setState({ isDisabled: true });
+        Policy.createWorkspace(undefined, undefined, undefined, undefined, () => this.setState({ isDisabled: false }));
+    }
+
     render() {
         const workspaces = this.getWorkspaces();
         return (
@@ -195,8 +207,9 @@ class WorkspacesListPage extends Component {
                 <FixedFooter style={[styles.flexGrow0]}>
                     <Button
                         success
+                        isDisabled={this.state.isDisabled}
                         text={this.props.translate('workspace.new.newWorkspace')}
-                        onPress={() => Policy.createWorkspace()}
+                        onPress={this.createNewWorkspace}
                     />
                 </FixedFooter>
             </ScreenWrapper>

Option 2: (Promise)

diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js
index c269accf6..032d4f27e 100644
--- a/src/libs/actions/Policy.js
+++ b/src/libs/actions/Policy.js
@@ -934,7 +934,7 @@ function createWorkspace(ownerEmail = '', makeMeAdmin = false, policyName = '',
         ],
     });
 
-    Navigation.isNavigationReady()
+    return Navigation.isNavigationReady()
         .then(() => {
             if (transitionFromOldDot) {
                 Navigation.dismissModal(); // Dismiss /transition route for OldDot to NewDot transitions
diff --git a/src/pages/workspace/WorkspacesListPage.js b/src/pages/workspace/WorkspacesListPage.js
index 5ef22eea7..faf2fb523 100755
--- a/src/pages/workspace/WorkspacesListPage.js
+++ b/src/pages/workspace/WorkspacesListPage.js
@@ -93,9 +93,16 @@ class WorkspacesListPage extends Component {
     constructor(props) {
         super(props);
 
+        this.state = {
+            isDisabled: false,
+        }
+
+
         this.getWalletBalance = this.getWalletBalance.bind(this);
         this.getWorkspaces = this.getWorkspaces.bind(this);
         this.getMenuItem = this.getMenuItem.bind(this);
+        this.createNewWorkspace = this.createNewWorkspace.bind(this);
+
     }
 
     /**
@@ -135,6 +142,8 @@ class WorkspacesListPage extends Component {
             .value();
     }
 
+    componentDidUpdate
+
     /**
      * Gets the menu item for each workspace
      *
@@ -171,6 +180,11 @@ class WorkspacesListPage extends Component {
         );
     }
 
+    createNewWorkspace() {
+        this.setState({ isDisabled: true });
+        Policy.createWorkspace().then(() => this.setState({ isDisabled: false }));
+    }
+
     render() {
         const workspaces = this.getWorkspaces();
         return (
@@ -195,8 +209,9 @@ class WorkspacesListPage extends Component {
                 <FixedFooter style={[styles.flexGrow0]}>
                     <Button
                         success
+                        isDisabled={this.state.isDisabled}
                         text={this.props.translate('workspace.new.newWorkspace')}
-                        onPress={() => Policy.createWorkspace()}
+                        onPress={this.createNewWorkspace}
                     />
                 </FixedFooter>
             </ScreenWrapper>

After Fix

Screen.Recording.2023-01-27.at.11.31.22.PM.mov

@melvin-bot
Copy link

melvin-bot bot commented Jan 27, 2023

Looks like something related to react-navigation may have been mentioned in this issue discussion.

As a reminder, please make sure that all proposals are not workarounds and that any and all attempt to fix the issue holistically have been made before proceeding with a solution. Proposals to change our DeprecatedCustomActions.js files should not be accepted.

Feel free to drop a note in #expensify-open-source with any questions.

@Puneet-here
Copy link
Contributor

Proposal

We can use a new onyx key to check if the workspace is being created and use that info to disable the button or set it to loading state

Add a new key IS_CREATING_NEW_WORKSPACE at ONYXKEYS

Change it's value to true when user presses the new workspace button like below at Policy.js

--- a/src/libs/actions/Policy.js
+++ b/src/libs/actions/Policy.js
@@ -762,6 +762,12 @@ function createWorkspace(ownerEmail = '', makeMeAdmin = false, policyName = '',
     },
     {
         optimisticData: [
+            {
+                onyxMethod: CONST.ONYX.METHOD.SET,
+                key: ONYXKEYS.IS_CREATING_NEW_WORKSPACE,
+                value: true,
+            },
+
             {
                 onyxMethod: CONST.ONYX.METHOD.SET,
                 key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
@@ -832,6 +838,11 @@ function createWorkspace(ownerEmail = '', makeMeAdmin = false, policyName = '',
             },
         ],
         successData: [
+            {
+                onyxMethod: CONST.ONYX.METHOD.SET,
+                key: ONYXKEYS.IS_CREATING_NEW_WORKSPACE,
+                value: false,
+            },
             {
                 onyxMethod: CONST.ONYX.METHOD.MERGE,
                 key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
@@ -896,6 +907,11 @@ function createWorkspace(ownerEmail = '', makeMeAdmin = false, policyName = '',
             },
         ],
         failureData: [
+            {
+                onyxMethod: CONST.ONYX.METHOD.SET,
+                key: ONYXKEYS.IS_CREATING_NEW_WORKSPACE,
+                value: false,
+            },
             {
                 onyxMethod: CONST.ONYX.METHOD.SET,
                 key: `${ONYXKEYS.COLLECTION.POLICY_MEMBER_LIST}${policyID}`,

Use the new key to set the button to loading (we can also disable it) like below at WorkspacesListPage

--- a/src/pages/workspace/WorkspacesListPage.js
+++ b/src/pages/workspace/WorkspacesListPage.js
@@ -197,6 +197,7 @@ class WorkspacesListPage extends Component {
                         success
                         text={this.props.translate('workspace.new.newWorkspace')}
                         onPress={() => Policy.createWorkspace()}
+                        isLoading={this.props.isCreatingNewWorkspace}
                     />
                 </FixedFooter>
             </ScreenWrapper>
@@ -223,5 +224,8 @@ export default compose(
         betas: {
             key: ONYXKEYS.BETAS,
         },
+        isCreatingNewWorkspace: {
+            key: ONYXKEYS.IS_CREATING_NEW_WORKSPACE,
+        },
     }),
 )(WorkspacesListPage);

@esh-g
Copy link
Contributor

esh-g commented Jan 27, 2023

@Puneet-here What would be the need to create an Onyx key for this? Why not just implement it in the state of the component itself?

@rushatgabhane
Copy link
Member

rushatgabhane commented Jan 27, 2023

Proposal:

How about we debounce the button?

onPress=_.debounce(createNewWorkspace, 250)

edit: third param can be set as true to trigger the on press call immediately

https://www.freecodecamp.org/news/javascript-debounce-example/

@priyeshshah11
Copy link
Contributor

priyeshshah11 commented Jan 28, 2023

Proposal

Problem

This issue will exist for all the buttons used throughout the app, thus I think we should fix this in the Button component itself.

Solution

We should disable the button until the onPress is completed, we can do this by passing a promise and wait for business logic before re-enabling the button where needed. Also, I am not sure whether this issue exists on 'Enter' presses too but if it is then we can apply the same logic there.

Note: We are applying a similar fix here #14426

diff --git a/src/components/Button.js b/src/components/Button.js
index 6e6fbade7..6854ae096 100644
--- a/src/components/Button.js
+++ b/src/components/Button.js
@@ -1,5 +1,7 @@
 import React, {Component} from 'react';
-import {Pressable, ActivityIndicator, View} from 'react-native';
+import {
+    Pressable, ActivityIndicator, View, InteractionManager,
+} from 'react-native';
 import PropTypes from 'prop-types';
 import styles from '../styles/styles';
 import themeColors from '../styles/themes/default';
@@ -144,6 +146,9 @@ const defaultProps = {
 class Button extends Component {
     constructor(props) {
         super(props);
+        this.state = {
+            isDisabled: props.isDisabled,
+        };
 
         this.renderContent = this.renderContent.bind(this);
     }
@@ -157,7 +162,7 @@ class Button extends Component {
 
         // Setup and attach keypress handler for pressing the button with Enter key
         this.unsubscribe = KeyboardShortcut.subscribe(shortcutConfig.shortcutKey, (e) => {
:...skipping...
diff --git a/src/components/Button.js b/src/components/Button.js
index 6e6fbade7..6854ae096 100644
--- a/src/components/Button.js
+++ b/src/components/Button.js
@@ -1,5 +1,7 @@
 import React, {Component} from 'react';
-import {Pressable, ActivityIndicator, View} from 'react-native';
+import {
+    Pressable, ActivityIndicator, View, InteractionManager,
+} from 'react-native';
 import PropTypes from 'prop-types';
 import styles from '../styles/styles';
 import themeColors from '../styles/themes/default';
@@ -144,6 +146,9 @@ const defaultProps = {
 class Button extends Component {
     constructor(props) {
         super(props);
+        this.state = {
+            isDisabled: props.isDisabled,
+        };
 
         this.renderContent = this.renderContent.bind(this);
     }
@@ -157,7 +162,7 @@ class Button extends Component {
 
         // Setup and attach keypress handler for pressing the button with Enter key
         this.unsubscribe = KeyboardShortcut.subscribe(shortcutConfig.shortcutKey, (e) => {
-            if (!this.props.isFocused || this.props.isDisabled || this.props.isLoading || (e && e.target.nodeName === 'TEXTAREA')) {
+            if (!this.props.isFocused || this.state.isDisabled || this.props.isLoading || (e && e.target.nodeName === 'TEXTAREA')) {
                 return;
             }
             e.preventDefault();
@@ -165,6 +170,14 @@ class Button extends Component {
         }, shortcutConfig.descriptionKey, shortcutConfig.modifiers, true, false, this.props.enterKeyEventListenerPriority, false);
     }
 
+    componentDidUpdate(prevProps) {
+        if (this.props.isDisabled === prevProps.isDisabled) {
+            return;
+        }
+
+        this.setState({isDisabled: this.props.isDisabled});
+    }
+
     componentWillUnmount() {
         // Cleanup event listeners
         if (!this.unsubscribe) {
@@ -234,6 +247,7 @@ class Button extends Component {
         return (
             <Pressable
                 onPress={(e) => {
+                    this.setState({isDisabled: true});
                     if (e && e.type === 'click') {
                         e.currentTarget.blur();
                     }
@@ -241,7 +255,16 @@ class Button extends Component {
                     if (this.props.shouldEnableHapticFeedback) {
                         HapticFeedback.trigger();
                     }
-                    this.props.onPress(e);
+                    const onPress = this.props.onPress(e);
+                    InteractionManager.runAfterInteractions(() => {
+                        if (!(onPress instanceof Promise)) {
+                            this.setState({isDisabled: this.props.isDisabled});
+                            return;
+                        }
+                        onPress.then(() => {
+                            this.setState({isDisabled: this.props.isDisabled});
+                        });
+                    });
                 }}
                 onLongPress={(e) => {
                     if (this.props.shouldEnableHapticFeedback) {
@@ -252,9 +275,9 @@ class Button extends Component {
                 onPressIn={this.props.onPressIn}
                 onPressOut={this.props.onPressOut}
                 onMouseDown={this.props.onMouseDown}
-                disabled={this.props.isLoading || this.props.isDisabled}
+                disabled={this.props.isLoading || this.state.isDisabled}
                 style={[
-                    this.props.isDisabled ? {...styles.cursorDisabled, ...styles.noSelect} : {},
+                    this.state.isDisabled ? {...styles.cursorDisabled, ...styles.noSelect} : {},
                     styles.buttonContainer,
                     this.props.shouldRemoveRightBorderRadius ? styles.noRightBorderRadius : undefined,
                     this.props.shouldRemoveLeftBorderRadius ? styles.noLeftBorderRadius : undefined,
@@ -263,7 +286,7 @@ class Button extends Component {
                 nativeID={this.props.nativeID}
             >
                 {({pressed, hovered}) => {
-                    const activeAndHovered = !this.props.isDisabled && hovered;
+                    const activeAndHovered = !this.state.isDisabled && hovered;
                     return (
                         <OpacityView
                             shouldDim={pressed}
@@ -274,9 +297,9 @@ class Button extends Component {
                                 this.props.large ? styles.buttonLarge : undefined,
                                 this.props.success ? styles.buttonSuccess : undefined,
                                 this.props.danger ? styles.buttonDanger : undefined,
-                                (this.props.isDisabled && this.props.success) ? styles.buttonSuccessDisabled : undefined,
-                                (this.props.isDisabled && this.props.danger) ? styles.buttonDangerDisabled : undefined,
-                                (this.props.isDisabled && !this.props.danger && !this.props.success) ? styles.buttonDisable : undefined,
+                                (this.state.isDisabled && this.props.success) ? styles.buttonSuccessDisabled : undefined,
+                                (this.state.isDisabled && this.props.danger) ? styles.buttonDangerDisabled : undefined,
+                                (this.state.isDisabled && !this.props.danger && !this.props.success) ? styles.buttonDisable : undefined,
                                 (this.props.success && activeAndHovered) ? styles.buttonSuccessHovered : undefined,
                                 (this.props.danger && activeAndHovered) ? styles.buttonDangerHovered : undefined,
                                 this.props.shouldRemoveRightBorderRadius ? styles.noRightBorderRadius : undefined,
diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js
index 5a2de0e7e..a47777d0c 100644
--- a/src/libs/actions/Policy.js
+++ b/src/libs/actions/Policy.js
@@ -698,6 +698,7 @@ function generatePolicyID() {
  * @param {Boolean} [makeMeAdmin] Optional, leave the calling account as an admin on the policy
  * @param {String} [policyName] Optional, custom policy name we will use for created workspace
  * @param {Boolean} [transitionFromOldDot] Optional, if the user is transitioning from old dot
+ * @returns {Promise} Navigation.isNavigationReady promise
  */
 function createWorkspace(ownerEmail = '', makeMeAdmin = false, policyName = '', transitionFromOldDot = false) {
     const policyID = generatePolicyID();
@@ -899,7 +900,7 @@ function createWorkspace(ownerEmail = '', makeMeAdmin = false, policyName = '',
         }],
     });
 
-    Navigation.isNavigationReady()
+    return Navigation.isNavigationReady()
         .then(() => {
             if (transitionFromOldDot) {
                 Navigation.dismissModal(); // Dismiss /transition route for OldDot to NewDot transitions

@mananjadhav @roryabraham

@melvin-bot melvin-bot bot added the Overdue label Jan 28, 2023
@sbsoso0411
Copy link

hey, @kavimuru
I've looked at the post at Upwork and now writing a proposal.

Above all, I can't really understand why all of the above proposals contain the code-panel. I don't wonna do that.

  1. So I can see that the issue is handling disable flag of the New Workspace Button. Now it is not working correctly when you click n times on the button in a very short time. correct?
  • To fix that, we should use ref feature in React. So createRef for class components and useRef for functional components.
  • Else, maybe we have another option. Do you know debounce? So we can avoid multiple calls of event listeners by debouncing the listener functions. Anyway the first solution would be better I think.
  1. Then why is that? What's the reason?
  • If you use state in react components to disable the button status, you can't avoid triple button click events. Because react state is only chagned when the component is re-rendered. But the event listeners can be called several times before re-rendering! So you can't avoid the issue using react state.
  • But ref is different. It uses the reference of the variable on memory. Which means it has its own absolute address on the memory. So even the action listener is called several times, once the variable changes, it is updated on the next-coming action listeners.

Hope my description is well-written and acceptable for you.
Looking forward to hearing from you.
Thank you.

@priyeshshah11
Copy link
Contributor

Above all, I can't really understand why all of the above proposals contain the code-panel. I don't wonna do that.

Hi @sbsoso0411, this might help you understand the process.

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!

@eh2077

This comment was marked as duplicate.

@fedirjh
Copy link
Contributor

fedirjh commented Jan 30, 2023

Proposal

When creating a new workspace, we set optimisticData for the new policy with a pendingAction of add. In WorkspacesListPage.js, we've already subscribed to the policies collection and have access to the new optimisticData. To avoid creating a new key as suggested by @puneet, we can filter the policies based on their pendingAction. When we find a policy with a pendingAction of add, then we set the button's isLoading prop to true.

diff --git a/src/pages/workspace/WorkspacesListPage.js b/src/pages/workspace/WorkspacesListPage.js
index 5ef22eea79..23049e0b1a 100755
--- a/src/pages/workspace/WorkspacesListPage.js
+++ b/src/pages/workspace/WorkspacesListPage.js
@@ -195,6 +195,10 @@ class WorkspacesListPage extends Component {
                 <FixedFooter style={[styles.flexGrow0]}>
                     <Button
                         success
+                        isLoading={_.some(
+                            workspaces,
+                            workspace => workspace && workspace.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
+                        )}
                         text={this.props.translate('workspace.new.newWorkspace')}
                         onPress={() => Policy.createWorkspace()}
                     />

@roryabraham
Copy link
Contributor

roryabraham commented Feb 1, 2023

We can add a callback function to [or return a promise from] the createWorkspace method that disables the button and enables it only after the workspace is successfully created ... What would be the need to create an Onyx key for this? Why not just implement it in the state of the component itself?

@esh-g We have established a pattern in this repo that:

  • API interactions should happen in src/libs/actions
  • Unless completely unavoidable, functions in src/libs/actions should not return a promise or be "chained"
  • Instead, the UI is just a representation of Onyx data, and doesn't ever directly wait for API events to finish

This sometimes leads to extra complexity (like when we create Onyx keys that really don't need to be written to disk), but sometimes all that's needed is a bit more creative thinking to find a clean solution that fits within our app's existing patterns.

So while your proposal is totally reasonable, it doesn't follow our patterns as closely as some others.


We can use a new onyx key to check if the workspace is being created and use that info to disable the button or set it to loading state

@Puneet-here this proposal shows a better understanding of our patterns, but overall I would really like to avoid adding any new Onyx keys for values that could instead be in-memory-only. We've discussed creating "ram-only" Onyx keys, but that project hasn't happened yet.

So overall, I personally would prefer @fedirjh's proposal that uses the pendingAction field of the workspace instead of a new IS_CREATING_NEW_WORKSPACE Onyx key. I think that would help keep our codebase cleaner. However, there might be a performance downside to that approach (explained below) and we're discussing in slack, so stay tuned.


@fedirjh My only concern about your idea to use the pendingAction field as written is that it requires us to loop over all policies. I think it might be too expensive to loop over all policies in a render function, since we have some customers that have thousands of policies.

I'm trying to think of a good way to handle this.


How about we debounce the button?

@rushatgabhane This might work, but overall it feels less robust than other solutions. What if you're on a slow internet connection and it takes 1600ms to create the policy?


This issue will exist for all the buttons used throughout the app, thus I think we should fix this in the Button component itself. We should disable the button until the onPress is completed, we can do this by passing a promise and wait for business logic before re-enabling the button where needed. Also, I am not sure whether this issue exists on 'Enter' presses too but if it is then we can apply the same logic there.
Note: We are applying a similar fix here #14426

@priyeshshah11 I like this approach a lot, like that it integrates InteractionManager, and like that it follows a pattern set by an existing PR. I also like that it solves the problem more globally and creates a blueprint to solve similar problems in the same way.

The main problem I see with your proposal is that it returns a Promise from an action in src/libs/actions, which as I said above to @esh-g is something we try to avoid in this repo.


[@sbsoso0411] Above all, I can't really understand why all of the above proposals contain the code-panel
[@priyeshshah11] Hi @sbsoso0411, this might help you understand the process.

I just wanted to set the record straight here. There is absolutely no requirement that you include actual code in your proposal. In fact, we consider writing a proposal in plain English to be a best practice. So I applaud @sbsoso0411 for simply explaining their proposal without just posting the code.

That said, if you're just joining us from Upwork, welcome! @priyeshshah11 gives good advice –read the contributing guidelines and join our slack rooms for the best contributing experience.


@sbsoso0411 I think your proposal is missing some important information - when do we disable/enable the button? What is the source of truth for when the button is enabled or disabled? However...

If you use state in react components to disable the button status, you can't avoid triple button click events. Because react state is only chagned when the component is re-rendered. But the event listeners can be called several times before re-rendering! So you can't avoid the issue using react state.
But ref is different. It uses the reference of the variable on memory. Which means it has its own absolute address on the memory. So even the action listener is called several times, once the variable changes, it is updated on the next-coming action listeners.

This is a great point, and something I wished we had thought of before implementing #14426 (cc @syedsaroshfarrukhdot @eVoloshchak)


In conclusion, many of the pieces of an ideal proposal are here, but I don't think any one proposal is quite right yet. Thanks for all your contributions so far, everyone!

@melvin-bot melvin-bot bot removed the Overdue label Feb 1, 2023
@Puneet-here
Copy link
Contributor

Thanks for the detailed feedback @roryabraham

@roryabraham
Copy link
Contributor

roryabraham commented Feb 1, 2023

@fedirjh My only concern about your idea to use the pendingAction field as written is that it requires us to loop over all policies. I think it might be too expensive to loop over all policies in a render function, since we have some customers that have thousands of policies.

Following up on this, I was wrong and I don't think we'll have a performance issue here. I tested it with this tiny script:

const _ = require('underscore');

const policies = {};
for (let i=0; i < 10000; i++) {
    if (i === 9999) {
        policies[i] = {pendingAction: 'add'};
    } else {
        policies[i] = {};
    }
}

const startTime = Date.now();
const isAnyPolicyPending = _.some(policies, policy => policy && policy.pendingAction === 'add');
const endTime = Date.now();

console.log(`Search took ${endTime - startTime} milliseconds`);

Even with 10000 items and a worst-case scenario where the random-generated policyID Onyx key is higher than any existing policyID, it only took like 3ms, so that should be fine.

@rushatgabhane
Copy link
Member

How about we debounce the button?
@rushatgabhane This might work, but overall it feels less robust than other solutions. What if you're on a slow internet connection and it takes 1600ms to create the policy?

@roryabraham i don't think it matters how long it takes for a policy to create.
When the debounce time is 250ms -> all button clicks that happen within 250ms will trigger a single onPress callback only.

image

https://www.freecodecamp.org/news/javascript-debounce-example/

please correct if I'm wrong.

@melvin-bot melvin-bot bot added the Awaiting Payment Auto-added when associated PR is deployed to production label May 16, 2023
@melvin-bot melvin-bot bot changed the title [$2000] Fast clicking any button 'n' times execute 'n' times [HOLD for payment 2023-05-23] [$2000] Fast clicking any button 'n' times execute 'n' times May 16, 2023
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label May 16, 2023
@melvin-bot
Copy link

melvin-bot bot commented May 16, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented May 16, 2023

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.3.14-14 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-05-23. 🎊

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

As a reminder, here are the bonuses/penalties that should be applied for any External issue:

  • Merged PR within 3 business days of assignment - 50% bonus
  • Merged PR more than 9 business days after assignment - 50% penalty

@melvin-bot
Copy link

melvin-bot bot commented May 16, 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:

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

@s77rt
Copy link
Contributor

s77rt commented May 17, 2023

  • The PR that introduced the bug has been identified: n/a. This existed since day one. It's more like a feature request than a bug.
  • The offending PR has been commented on: n/a
  • A discussion in #expensify-bugs has been started: n/a
  • Determine if we should create a regression test for this bug: No

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Daily KSv2 Weekly KSv2 and removed Weekly KSv2 Daily KSv2 labels May 22, 2023
@melvin-bot melvin-bot bot changed the title [HOLD for payment 2023-05-23] [$2000] Fast clicking any button 'n' times execute 'n' times [HOLD for payment 2023-06-01] [HOLD for payment 2023-05-23] [$2000] Fast clicking any button 'n' times execute 'n' times May 25, 2023
@melvin-bot
Copy link

melvin-bot bot commented May 25, 2023

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

@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label May 25, 2023
@melvin-bot
Copy link

melvin-bot bot commented May 25, 2023

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.3.17-5 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-06-01. 🎊

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

As a reminder, here are the bonuses/penalties that should be applied for any External issue:

  • Merged PR within 3 business days of assignment - 50% bonus
  • Merged PR more than 9 business days after assignment - 50% penalty

@melvin-bot
Copy link

melvin-bot bot commented May 25, 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:

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

@priyeshshah11
Copy link
Contributor

@roryabraham can some other BZ member be assigned to this issue to issue payments & ultimately answer this as @slafortune is OOO as mentioned here.

@s77rt
Copy link
Contributor

s77rt commented May 25, 2023

  • The PR that introduced the bug has been identified: Not really a bug. This is more like a feature request.
  • The offending PR has been commented on: n/a
  • A discussion in #expensify-bugs has been started: n/a
  • Determine if we should create a regression test for this bug: No, I don't feel like this kind of issues are something that should be covered in a regression test.

@slafortune
Copy link
Contributor

Thanks @s77rt !

Trying to get a clear handle on who should be getting paid on this - seems there are 2 C+ assigned.

@slafortune
Copy link
Contributor

Working with @roryabraham on this. I am out of the office, but checking back on this.

@priyeshshah11
Copy link
Contributor

@roryabraham can some other BZ member be assigned to this issue to issue payments & ultimately answer this as @slafortune is OOO as mentioned here.

@slafortune / @roryabraham any updates here?

@slafortune
Copy link
Contributor

Hey @priyeshshah11 - Looks like payment is on hold until 6/1 and also I believe that @roryabraham is still looking into this, we'll update soon

@priyeshshah11
Copy link
Contributor

all good @slafortune, just saying that originally the payment was on hold till 05/23 & then linking a second PR caused the automation to run & change that to 6/1 which shouldn't have been the case as it was only a word change & didn't change any functionality.

@roryabraham
Copy link
Contributor

Ok, catching up here after some OOO. I think the following payments are due:

  • $2,000 to @mananjadhav for C+ reviews
  • $2,000 to @s77rt for C+ reviews. I don't have all the context for why @mountiny assigned a second C+ here in April, but both @mananjadhav and @s77rt triaged, tested, and reviewed, so they should both be paid.
  • $2,000 to @priyeshshah11 for the PR. I think the delay was warranted because whenever a new PR is merged to fix something missing with the previous one the timer is supposed to restart AFAIK. In any event, it shouldn't matter too much either way because the payment should be issued tomorrow.

@slafortune
Copy link
Contributor

Thanks so much @roryabraham
@priyeshshah11 thanks for your patience and quickly accepting! all paid 👍

@mountiny
Copy link
Contributor

mountiny commented Jun 1, 2023

@roryabraham thanks! for context I have assigned C+ after posting here as at the time the conversation was stale and C+ hasnt posted anything assuming they needed help.

Glad we got tot he bottom of this ❤️

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. External Added to denote the issue can be worked on by a contributor Weekly KSv2
Projects
None yet
Development

No branches or pull requests