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

Remove setTimeout(). Fix behavior of create menu. #8827

Merged
merged 13 commits into from
May 3, 2022

Conversation

marcaaron
Copy link
Contributor

@marcaaron marcaaron commented Apr 28, 2022

Details

@Beamanator @luacmartins I don't think we need this setTimeout() anymore. Since this was moved into WelcomeActions it seems to open the create menu on iOS just fine.

I removed the setTimeout() and tested on a few versions of iOS and it works fine.

Fixed Issues

$ #5296
Regression caused by: #8692

Tests (iOS)

  1. Sign in as a new user
  2. Verify the create menu opens
  • Verify that no errors appear in the JS console

PR Review Checklist

PR Reviewer Checklist

  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible 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 checked that screenshots or videos are included for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • 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 verified proper code patterns were followed (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 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 was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and approved by marketing by tagging the marketing team 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 verified that this PR follows the guidelines as stated in the Review Guidelines
  • 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
  • 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 */
    • Any functional components have the displayName property
    • 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
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • 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 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 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.

QA Steps

  1. Sign in as a new user
  2. Verify the create menu opens
  • Verify that no errors appear in the JS console

Screenshots

Web

2022-05-02_11-31-27.mp4

Mobile Web

2022-05-02_12-44-14.mp4

Desktop

2022-05-02_12-42-19.mp4

iOS

2022-04-28_12-22-57.mp4

Android

XRecorder_02052022_115912.mp4

@marcaaron marcaaron requested a review from a team as a code owner April 28, 2022 22:28
@marcaaron marcaaron self-assigned this Apr 28, 2022
@melvin-bot melvin-bot bot requested review from techievivek and removed request for a team April 28, 2022 22:28
techievivek
techievivek previously approved these changes Apr 29, 2022
Copy link
Contributor

@techievivek techievivek left a comment

Choose a reason for hiding this comment

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

Works smoothly.

Copy link
Contributor

@Beamanator Beamanator left a comment

Choose a reason for hiding this comment

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

A few minor comments - tests well!

Comment on lines 18 to 20
function show({
routes, showCreateMenu, isFirstTimeNewExpensifyUser, allReports, allPolicies,
}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nab; is a lint rule enforcing doing this on multiple lines? Or personal preference? My personal preference is to keep this 1 line 😅 but def not super worried about it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, it was the linter. I don't have any strong feelings on this though - we can change the linter if it bothers enough people 😄

@github-actions
Copy link
Contributor

⚠️ ⚠️ Heads up! This pull request has the CP Staging label. ⚠️ ⚠️
Merging it will cause it to be immediately deployed to staging, even if the open StagingDeployCash deploy checklist is locked.

@marcaaron
Copy link
Contributor Author

Thanks for the comments @Beamanator. Updated!

Copy link
Contributor

@kidroca kidroca left a comment

Choose a reason for hiding this comment

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

I don't know how others tests this but here's what I did to recreate a related bug

Add a delay for retrieving the NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER key
Longer delays recreate the bug more consistently

  1. Update the code with the example below and play with the timeout (I managed to reduce the timeout to 1000 and still recreate the bug)
  2. Be logged out
  3. Log in
  4. Observe that even though we're not a first time user "create menu" is opened automatically

src/libs/actions/NameValuePair.js

/**
 * Gets the value of an NVP
 *
 * @param {String} name
 * @param {String} onyxKey
 * @param {*} [defaultValue]
 */
function get(name, onyxKey, defaultValue) {
    API.Get({
        returnValueList: 'nameValuePairs',
        name,
    })
        .then((response) => {
            if (name === 'isFirstTimeNewExpensifyUser') {
                setTimeout(() => {
                    console.warn('Overriding isFirstTimeNewExpensifyUser');
                    Onyx.set(onyxKey, false);
                }, 1250);
                return;
            }

            const value = lodashGet(response.nameValuePairs, [name], defaultValue || '');
            Onyx.set(onyxKey, value);
        });
}

If the NVP request is slow enough the "Create Menu" will star opened (even if NVP resolves to false)(only after login / clean onyx)
Seems like the old 1500 delay was covering this issue as well

We need to either check that we already have a false value stored in Onyx, or wait for the NVP request to be over before evaluating whether to show the "create menu" or not


The setTimeout seem no longer needed otherwise

Comment on lines 64 to 66
isFirstTimeNewExpensifyUser: _.isBoolean(this.props.isFirstTimeNewExpensifyUser)
? this.props.isFirstTimeNewExpensifyUser
: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Usually we'll be using defaultProps for this
Maybe because value comes from Onyx, it'll might be null despite a default prop value?

BTW isFirstTimeNewExpensifyUser isn't added to propTypes either

@kidroca
Copy link
Contributor

kidroca commented Apr 29, 2022

Maybe we can wait for a boolean value to be added for NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER in Onyx and then open the create menu if necessary?

  1. componentDidMount passes show/hide methods to WellcomeActions
  2. WellcomeActions subscribe to Onyx
  3. When boolean value is returned from the subscription it disconnects
  4. If the value is true the "create menu is displayed"

@marcaaron
Copy link
Contributor Author

Longer delays recreate the bug more consistently

Thanks @kidroca, just to clarify here the bug is:

The create menu is showing when we are not a new user because we must wait to know the true value of isFirstTimeNewExpensifyUser from the server

?

@marcaaron
Copy link
Contributor Author

Does seem like we would probably want to wait for the reports and policies in that case as well 🤔

@marcaaron
Copy link
Contributor Author

Gonna try something else here. I think it will be too confusing to have this logic in the view and we can't get around the fact that we need to wait for data to arrive from the server in this case 😄

@marcaaron
Copy link
Contributor Author

marcaaron commented Apr 29, 2022

Ok tried a different approach. I'm not sure if it's super great, but I believe it to be more correct than what we had before and here's my full reasoning...

Fact 1:

  • The "welcome action" must only happen until after we have read these values from the server:
    • isFirstTimeNewExpensifyUser
    • allPolicies
    • allReports

I can't think of a way around this right now, but that seems like the primary reason why we have the setTimeout()

Fact 2:

  • We can't trigger the "welcome task" until the Sidebar mounts so calling WelcomeActions.show() once in componentDidMount() seems correct. This guarantees the modal is ready to open, etc.

Fact 3:

  • We don't have a great way to detect whether the data we need has loaded from inside the SidebarScreen.

This is a new one for me, but I observed that the value of something like isReportDataLoading can be quickly set before the SidebarScreen even mounts. If we wanted to move that logic into the view layer it would be kind of ugly and require we do some checks inside componentDidUpdate() to see if the data has "loaded" yet. But if it loads before the component even mounts then we'd never be able to know that happened from inside the component because it's possible that a first time user sign in will:

  • quickly fetch the report data
  • mount the SidebarScreen
  • give us no way to tell from within SidebarScreen that we have loaded all the reports, policies, or anything else

Sometimes a component needs to know whether we have at least attempted to load data from the server once and that the data it gets from withOnyx is the most up to date based on that data load.

It's not clear how often we might run into this situation, but I feel a more correct approach would be one where the component that needs to know whether this data has loaded would be the one to trigger it. Or we could create some kind of "monitor" that allows any component or lib to know if data has been loaded from the server for the current session.

luacmartins
luacmartins previously approved these changes May 2, 2022
Copy link
Contributor

@luacmartins luacmartins left a comment

Choose a reason for hiding this comment

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

The new solution works well and LGTM. Should we add videos for all platforms?

@marcaaron
Copy link
Contributor Author

marcaaron commented May 2, 2022

Should we add videos for all platforms?

I can. It will take me some time to do :D Done

@marcaaron marcaaron dismissed Beamanator’s stale review May 2, 2022 21:05

Changes no longer relevant

Comment on lines 34 to +58
Onyx.connect({
key: ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER,
callback: val => isFirstTimeNewExpensifyUser = val,
initWithStoredValues: false,
callback: (val) => {
isFirstTimeNewExpensifyUser = val;
checkOnReady();
},
});

Onyx.connect({
key: ONYXKEYS.IS_LOADING_REPORT_DATA,
initWithStoredValues: false,
callback: (val) => {
isLoadingReportData = val;
checkOnReady();
},
});

Onyx.connect({
key: ONYXKEYS.IS_LOADING_POLICY_DATA,
initWithStoredValues: false,
callback: (val) => {
isLoadingPolicyData = val;
checkOnReady();
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a big deal, but after setReady we no longer need to be connected to these Onyx keys

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually we might need - for when you logout and login again

@@ -8,17 +8,60 @@ import * as Policy from './Policy';
import ONYXKEYS from '../../ONYXKEYS';
import NameValuePair from './NameValuePair';
import CONST from '../../CONST';
import createOnReadyTask from '../createOnReadyTask';

const [isReady, setReady] = createOnReadyTask();
Copy link
Contributor

@kidroca kidroca May 3, 2022

Choose a reason for hiding this comment

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

Would isReady remain resolved if we logout and login with another account?

I guess chances are slim, but if you login, logout, then login with a new user, they might not have the "Create Menu" opened

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a nice example for a static (libs) vs instance (component) based code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point and nope, but I made this task resettable in another PR so let me see about that...

@marcaaron
Copy link
Contributor Author

Updated, thanks for the spot @kidroca

@marcaaron
Copy link
Contributor Author

Gonna be bold and merge this since I think it is blocking the deploy...?

@marcaaron marcaaron merged commit 334b989 into main May 3, 2022
@marcaaron marcaaron deleted the marcaaron-fixSetTimeout branch May 3, 2022 22:56
@marcaaron
Copy link
Contributor Author

@sketchydroide my CP staging label didn't seem to work here 🤔 despite this comment and this one I am pretty sure this needs to staging. But let me know if I missed something.

OSBotify pushed a commit that referenced this pull request May 3, 2022
Remove `setTimeout()`. Fix behavior of create menu.

(cherry picked from commit 334b989)
@kbecciv
Copy link

kbecciv commented May 6, 2022

@marcaaron

Login- Create menu is not open

Action Performed:

  1. Go to staging.new.expensifail.com
  2. Sign in as a new user
  3. Go back to your email and click on Link
  4. Change the URL to staging and set a password for a new user
  5. Verify the create menu opens

Expected Result:

The create menu opens

Actual Result:

Create menu is not open

Workaround:

Unknown

Platform:

Where is this issue occurring?

  • Web
  • iOS
  • Android
  • Desktop App
  • Mobile Web

Version Number: 1.1.57.7

Notes/Photos/Videos: Any additional supporting documentation

Recording.350.mp4

@marcaaron
Copy link
Contributor Author

@kbecciv doesn't appear to be on staging yet...

sketchydroide added a commit that referenced this pull request May 6, 2022
@kbecciv
Copy link

kbecciv commented May 9, 2022

@marcaaron Issue is not fixed. #8827 (comment)

Recording.365.mp4

@sketchydroide
Copy link
Contributor

the code seems to be on staging, let me check if the build for it was deployed

@kbecciv
Copy link

kbecciv commented May 9, 2022

@sketchydroide We tested on 1.1.57.7 build and it failed

OSBotify pushed a commit that referenced this pull request May 9, 2022
Remove `setTimeout()`. Fix behavior of create menu.

(cherry picked from commit 334b989)
Beamanator added a commit that referenced this pull request May 9, 2022
…ging-8827

🍒 Cherry pick PR #8827 to staging 🍒
@chiragsalian
Copy link
Contributor

CP code to staging, there is no post about it because the automated steps failed. Either way, this fix should be testable on version 1.1.57-8. I tested it on web and native mobile and it looks like the issue is resolved but can you re-test as well @kbecciv?

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.

8 participants