Repository navigation
Reapply onyx upgrade use cache with fixes #24041
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
Changes from all commits
f462336
8558d74
cd62597
c022440
79c8565
cb43f6b
a3e0e82
1c92993
0a230de
54ef4ef
8b0443a
f28bf18
6f9da52
53323f0
b0d81a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,7 +83,6 @@ const defaultProps = { | |
| isSubmitButtonVisible: true, | ||
| formState: { | ||
| isLoading: false, | ||
| errors: null, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NAB: I assume crash was fixed in onyx repo. Now what's this removal for?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The crash wasn't fixed in the onyx repo. It is invalid when looking at the logic of the component to have errors as null. It's never expected to be null.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't find the exact bug ticket at the moment. I know it was one of the bugs that was found during going through the regressions here: https://expensify.slack.com/archives/C01GTK53T8Q/p1690897222550089 Have to leave for vacation in a few minutes so I can't find it right now, sorry 😓
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nvm. Hopefully this PR and #18648 would be merged without further change requests from you. Have a good vacation! |
||
| }, | ||
| draftValues: {}, | ||
| enabledWhenOffline: false, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,18 +96,6 @@ class BaseOptionsSelector extends Component { | |
| ); | ||
|
|
||
| this.scrollToIndex(this.props.selectedOptions.length ? 0 : this.state.focusedIndex, false); | ||
|
|
||
| if (!this.props.autoFocus) { | ||
| return; | ||
| } | ||
|
|
||
| if (this.props.shouldShowTextInput) { | ||
| if (this.props.shouldDelayFocus) { | ||
| this.focusTimeout = setTimeout(() => this.textInput.focus(), CONST.ANIMATED_TRANSITION); | ||
| } else { | ||
| this.textInput.focus(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| componentDidUpdate(prevProps) { | ||
|
|
@@ -339,6 +327,8 @@ class BaseOptionsSelector extends Component { | |
| selectTextOnFocus | ||
| blurOnSubmit={Boolean(this.state.allOptions.length)} | ||
| spellCheck={false} | ||
| autoFocus={this.props.autoFocus} | ||
| shouldDelayFocus={this.props.shouldDelayFocus} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirmed that this fixes Keyboard opens multiple times when selecting members to request money.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is mostly an order of event issue. Now, when we navigate to a new screen there is some code in react-navigation that will dismiss the keyboard when we transition to a new screen. When the focus happens on the class component componentDidMount the order of events is the following:
Now, we call the focus from the useEffect, and the order of events is roughly this:
|
||
| /> | ||
| ); | ||
| const optionsList = ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,10 +70,11 @@ Onyx.connect({ | |
| /** | ||
| * Reset money request info from the store with its initial value | ||
| * @param {String} id | ||
| * @returns {Promise} | ||
| */ | ||
| function resetMoneyRequestInfo(id = '') { | ||
| const date = currentDate || moment().format('YYYY-MM-DD'); | ||
| Onyx.merge(ONYXKEYS.IOU, { | ||
| return Onyx.merge(ONYXKEYS.IOU, { | ||
| id, | ||
| amount: 0, | ||
| currency: lodashGet(currentUserPersonalDetails, 'localCurrencyCode', CONST.CURRENCY.USD), | ||
|
|
@@ -1464,53 +1465,61 @@ function payMoneyRequest(paymentType, chatReport, iouReport) { | |
| * Initialize money request info and navigate to the MoneyRequest page | ||
| * @param {String} iouType | ||
| * @param {String} reportID | ||
| * @returns {Promise} | ||
| */ | ||
| function startMoneyRequest(iouType, reportID = '') { | ||
| resetMoneyRequestInfo(`${iouType}${reportID}`); | ||
| Navigation.navigate(ROUTES.getMoneyRequestRoute(iouType, reportID)); | ||
| return resetMoneyRequestInfo(`${iouType}${reportID}`).then(() => { | ||
| Navigation.navigate(ROUTES.getMoneyRequestRoute(iouType, reportID)); | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's pretty uncommon to have to wait for a merge to navigate. If we are going to chain off of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the problem here is that now when we have withOnyx improvement we may sometimes read outdate value. For instance we have a screen that operates on value "X". Let say we had a flow that first modifies the value "X" then navigates to our screen. Before what was happening is withOnyx wrapped screen was waiting for onyx values by waiting for connect method and then info about value "X". in connect method there were a lot of promises so we were sure that our modification was succeeded before we actually rendered content of the new screen. Now it's possible that we will modify the "X" navigate to screen read previous value of "X" from cache then once modification takes place we render the component one more time.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. waiting for merge prevents reading outdate value from what I understand
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can easily miss some cases as previously we didn't need to care about it as we were sure that we won't read from onyx before the modification happen.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can do it in a bit safer way (but you better now how many such cases we can have in the app. Maybe those from the pr are the only ones) withOnyx({
allowReadingStaleData: true
})Then on every merge/set/remove we update two simple maps so we know if the data in cache is up to date if the data is stale we don't get it from cache in withOnyx wrapper unless someone set |
||
| } | ||
|
|
||
| /** | ||
| * @param {String} id | ||
| * @returns {Promise} | ||
| */ | ||
| function setMoneyRequestId(id) { | ||
| Onyx.merge(ONYXKEYS.IOU, {id}); | ||
| return Onyx.merge(ONYXKEYS.IOU, {id}); | ||
| } | ||
|
|
||
| /** | ||
| * @param {Number} amount | ||
| * @returns {Promise} | ||
| */ | ||
| function setMoneyRequestAmount(amount) { | ||
| Onyx.merge(ONYXKEYS.IOU, {amount}); | ||
| return Onyx.merge(ONYXKEYS.IOU, {amount}); | ||
| } | ||
|
|
||
| /** | ||
| * @param {String} currency | ||
| * @returns {Promise} | ||
| */ | ||
| function setMoneyRequestCurrency(currency) { | ||
| Onyx.merge(ONYXKEYS.IOU, {currency}); | ||
| return Onyx.merge(ONYXKEYS.IOU, {currency}); | ||
| } | ||
|
|
||
| /** | ||
| * @param {String} comment | ||
| * @returns {Promise} | ||
| */ | ||
| function setMoneyRequestDescription(comment) { | ||
| Onyx.merge(ONYXKEYS.IOU, {comment: comment.trim()}); | ||
| return Onyx.merge(ONYXKEYS.IOU, {comment: comment.trim()}); | ||
| } | ||
|
|
||
| /** | ||
| * @param {Object[]} participants | ||
| * @returns {Promise} | ||
| */ | ||
| function setMoneyRequestParticipants(participants) { | ||
| Onyx.merge(ONYXKEYS.IOU, {participants}); | ||
| return Onyx.merge(ONYXKEYS.IOU, {participants}); | ||
| } | ||
|
|
||
| /** | ||
| * @param {String} receiptPath | ||
| * @param {String} receiptSource | ||
| * @returns {Promise} | ||
| */ | ||
| function setMoneyRequestReceipt(receiptPath, receiptSource) { | ||
| Onyx.merge(ONYXKEYS.IOU, {receiptPath, receiptSource}); | ||
| return Onyx.merge(ONYXKEYS.IOU, {receiptPath, receiptSource}); | ||
| } | ||
|
|
||
| function createEmptyTransaction() { | ||
|
|
@@ -1530,10 +1539,11 @@ function createEmptyTransaction() { | |
| function navigateToNextPage(iou, iouType, reportID, report) { | ||
| const moneyRequestID = `${iouType}${reportID}`; | ||
| const shouldReset = iou.id !== moneyRequestID; | ||
| const promises = []; | ||
| // If the money request ID in Onyx does not match the ID from params, we want to start a new request | ||
| // with the ID from params. We need to clear the participants in case the new request is initiated from FAB. | ||
| if (shouldReset) { | ||
| resetMoneyRequestInfo(moneyRequestID); | ||
| promises.push(resetMoneyRequestInfo(moneyRequestID)); | ||
| } | ||
|
|
||
| // If a request is initiated on a report, skip the participants selection step and navigate to the confirmation page. | ||
|
|
@@ -1547,12 +1557,29 @@ function navigateToNextPage(iou, iouType, reportID, report) { | |
| .filter((accountID) => currentUserAccountID !== accountID) | ||
| .map((accountID) => ({accountID, selected: true})) | ||
| .value(); | ||
| setMoneyRequestParticipants(participants); | ||
| promises.push(setMoneyRequestParticipants(participants)); | ||
| } | ||
| Navigation.navigate(ROUTES.getMoneyRequestConfirmationRoute(iouType, reportID)); | ||
| Promise.all(promises).then(() => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar comment here. Pushing all these merge promises into the array has made this code harder to reason about I think. We should document every reason why we will need to await an |
||
| Navigation.navigate(ROUTES.getMoneyRequestConfirmationRoute(iouType, reportID)); | ||
| }); | ||
| return; | ||
| } | ||
| Navigation.navigate(ROUTES.getMoneyRequestParticipantsRoute(iouType)); | ||
|
|
||
| Promise.all(promises).then(() => { | ||
| Navigation.navigate(ROUTES.getMoneyRequestParticipantsRoute(iouType)); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * @param {String} receiptPath | ||
| * @param {String} receiptSource | ||
| * @param {String} iouType | ||
| * @param {String} reportID | ||
| * @param {Object} report | ||
| * @returns {Promise} | ||
| */ | ||
| function setMoneyRequestReceiptAndNavigateToNextPage(receiptPath, receiptSource, iouType, reportID, report) { | ||
| return setMoneyRequestReceipt(receiptPath, receiptSource).then(() => navigateToNextPage(ONYXKEYS.IOU, iouType, reportID, report)); | ||
| } | ||
|
|
||
| export { | ||
|
|
@@ -1574,4 +1601,5 @@ export { | |
| setMoneyRequestReceipt, | ||
| createEmptyTransaction, | ||
| navigateToNextPage, | ||
| setMoneyRequestReceiptAndNavigateToNextPage, | ||
| }; | ||
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.
What issue was fixed by this removal?
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 one #24041 (comment)
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 was originally added in #8221 to fix emoji select on first tap not working on android.
I confirmed that's not reproducible after revert.
8.mov
Uh oh!
There was an error while loading. Please reload this page.
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.
Hi, in my test, after removing this code, the keyboard no longer appears when dismissing the emoji modal on Android native.
test.mp4
How about moving
Keyboard.dismiss()into theonPresshandler inEmojiPickerButton? This could fix #24041 (comment) without impacting Android platform.App/src/components/EmojiPicker/EmojiPickerButton.js
Lines 47 to 53 in 00efce4
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.
Hey @ntdiary
You are saying
The code here is about dismissing the keyboard. I'd never expect this code to open the keyboard?
Uh oh!
There was an error while loading. Please reload this page.
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.
Ah, this may seem a bit unbelievable 😂, but let me explain a bit more: as shown in the image above, for android, if we don't manually call
blur( ordismiss), the focus state inside the composer input box will not change when opening the emoji modal. Then after we close the modal, even though we callfocuson the composer input box, because the internal focus state did not change, the part where the keyboard is supposed to show gets ignored.So here,
dismisscan clean up the internal focus state, allowing the subsequentfocusto successfully show the keyboard.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.
oh wow, I didn't know that, thanks for sharing!! So you say we should add this code back? 😊
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 was also surprised when I first discovered this android behavior. And don't worry, I just made a note here, we still have another issue and may do something there as needed. 😄