-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works smoothly.
There was a problem hiding this 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!
src/libs/actions/WelcomeActions.js
Outdated
function show({ | ||
routes, showCreateMenu, isFirstTimeNewExpensifyUser, allReports, allPolicies, | ||
}) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 😄
|
Thanks for the comments @Beamanator. Updated! |
There was a problem hiding this 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
- 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)
- Be logged out
- Log in
- 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
isFirstTimeNewExpensifyUser: _.isBoolean(this.props.isFirstTimeNewExpensifyUser) | ||
? this.props.isFirstTimeNewExpensifyUser | ||
: true, |
There was a problem hiding this comment.
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
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?
|
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 ? |
Does seem like we would probably want to wait for the reports and policies in that case as well 🤔 |
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 😄 |
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:
I can't think of a way around this right now, but that seems like the primary reason why we have the Fact 2:
Fact 3:
This is a new one for me, but I observed that the value of something like
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 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. |
There was a problem hiding this 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?
|
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(); | ||
}, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
src/libs/actions/Welcome.js
Outdated
@@ -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(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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...
Updated, thanks for the spot @kidroca |
Gonna be bold and merge this since I think it is blocking the deploy...? |
@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. |
Remove `setTimeout()`. Fix behavior of create menu. (cherry picked from commit 334b989)
Login- Create menu is not openAction Performed:
Expected Result:The create menu opens Actual Result:Create menu is not open Workaround:Unknown Platform:Where is this issue occurring?
Version Number: 1.1.57.7 Notes/Photos/Videos: Any additional supporting documentation Recording.350.mp4 |
@kbecciv doesn't appear to be on staging yet... |
…8827 🍒 Cherry pick PR #8827 to staging 🍒
@marcaaron Issue is not fixed. #8827 (comment) Recording.365.mp4 |
the code seems to be on staging, let me check if the build for it was deployed |
@sketchydroide We tested on 1.1.57.7 build and it failed |
Remove `setTimeout()`. Fix behavior of create menu. (cherry picked from commit 334b989)
…ging-8827 🍒 Cherry pick PR #8827 to staging 🍒
CP code to staging, there is no post about it because the automated steps failed. Either way, this fix should be testable on version |
Details
@Beamanator @luacmartins I don't think we need this
setTimeout()
anymore. Since this was moved intoWelcomeActions
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)
PR Review Checklist
PR Reviewer Checklist
### Fixed Issues
section aboveTests
sectionQA steps
sectiontoggleReport
and notonIconClick
).src/languages/*
filesSTYLE.md
) were followed/** comment above it */
displayName
propertythis
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)QA Steps
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