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

HIGH: Kill ReconnectToReport #34902

Merged
merged 12 commits into from
Apr 3, 2024
Merged

Conversation

aldo-expensify
Copy link
Contributor

@aldo-expensify aldo-expensify commented Jan 22, 2024

Details

In the context of optimizing ReconnectToReport, we are proposing to just get rid of it since it became redundant after reliable updates was implemented.

ReconnectToReport command was introduced to get the missing reportActions after coming back online. This was necessary because ReconnectApp didn't get reportActions, but now that we have "reliable updates", we are able to fetch and retrieve the missed Onyx updates which contain the missing report Actions (The missed updates are returned by ReconnectApp).

Fixed Issues

$ #39464
$ https://github.com/Expensify/Expensify/issues/325231
PROPOSAL:

Tests

1. Report created while offline

  1. Create accountA and accountB, and log them in on different sessions
  2. Make accountA go offline
  3. Using accountB, create a DM chat with accountA and send a message
  4. Make accountA go online
  5. Verify that accountA gets the DM chat with accountB and gets all messages
  6. Send a message with accountB
  7. Verify that accountA received the last message

2. Switching from being an anonymousAccount to a normal one while looking at a public room

  1. Create a public room and copy the room URL
  2. Sign out
  3. Go to public room by URL from step 1
  4. Log in with a very new account
  5. Verify that whisper message from Concierge displays
    image

3. Going offline/online with the report screen open

Almost the same as test 1. Report created while offline, but the accountA goes offline after loading the report.

  1. Create accountA and accountB, and log them in on different sessions
  2. Using accountB, create a DM chat with accountA and send a message
  3. Verify that accountA receives the DM chat with accountB and the messages
  4. With accountA, leave the DM chat open and go offline
  5. Send a message with accountB
  6. Make accountA go online
  7. Verify that accountA receives the last message
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

1. Report created while offline

  1. Create accountA and accountB, and log them in on different sessions
  2. Make accountA go offline
  3. Using accountB, create a DM chat with accountA and send a message
  4. Make accountA go online
  5. Verify that accountA gets the DM chat with accountB and gets all messages
  6. Send a message with accountB
  7. Verify that accountA received the last message

2. Switching from being an anonymousAccount to a normal one while looking at a public room

  1. Create a public room and copy the room URL
  2. Sign out
  3. Go to public room by URL from step 1
  4. Log in with a very new account
  5. Verify that whisper message from Concierge displays
    image

3. Going offline/online with the report screen open

Almost the same as test 1. Report created while offline, but the accountA goes offline after loading the report.

  1. Create accountA and accountB, and log them in on different sessions
  2. Using accountB, create a DM chat with accountA and send a message
  3. Verify that accountA receives the DM chat with accountB and the messages
  4. With accountA, leave the DM chat open and go offline
  5. Send a message with accountB
  6. Make accountA go online
  7. Verify that accountA receives the last message
  • 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: mWeb Chrome
    • iOS: Native
    • iOS: mWeb 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 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(theme.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 the PR modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label so the design team can review the changes.
  • 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.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

1. Report created while offline

Screen.Recording.2024-01-22.at.12.21.45.PM.mov

2. Switching from being an anonymousAccount to a normal one while looking at a public room

Screen.Recording.2024-01-22.at.4.56.34.PM.mov

3. Going offline/online with the report screen open

Screen.Recording.2024-01-22.at.5.35.03.PM.mov
MacOS: Desktop

@aldo-expensify aldo-expensify self-assigned this Jan 22, 2024
Comment on lines 142 to 122
if (isReportFullyVisible) {
openReportIfNecessary();
} else {
Report.reconnect(reportID);
}
openReportIfNecessary();
Copy link
Contributor Author

@aldo-expensify aldo-expensify Jan 22, 2024

Choose a reason for hiding this comment

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

This is the only case we still need to fetch report with OpenReport because this is not related to loosing/regaining connection, so ReconnectApp is not called.

In the past, we were call Report.reconnect(reportID); instead of openReportIfNecessary(); if the App is in the background/not focused, but I don't think it is important to have this consideration here because this case only happens when we are login in from an anonymous account, and we can't log in with the app in the background.

Comment on lines 121 to 137
useEffect(() => {
const prevNetwork = prevNetworkRef.current;
// When returning from offline to online state we want to trigger a request to OpenReport which
// will fetch the reportActions data and mark the report as read. If the report is not fully visible
// then we call ReconnectToReport which only loads the reportActions data without marking the report as read.
const wasNetworkChangeDetected = lodashGet(prevNetwork, 'isOffline') && !lodashGet(props.network, 'isOffline');
if (wasNetworkChangeDetected) {
if (isReportFullyVisible) {
openReportIfNecessary();
} else {
Report.reconnect(reportID);
}
}
// update ref with current network state
prevNetworkRef.current = props.network;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [props.network, props.report, isReportFullyVisible]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not needed anymore because ReconnectApp will fetch the missing updates

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds right to me.

Comment on lines -1101 to -1190
if (report.reportID && report.reportName === undefined) {
reconnect(report.reportID);
}
Copy link
Contributor Author

@aldo-expensify aldo-expensify Jan 22, 2024

Choose a reason for hiding this comment

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

TODO: Need to make sure this isn't needed. If reliable updates works properly, I don't think we should miss a report, but 🤷

Copy link
Contributor Author

@aldo-expensify aldo-expensify Jan 22, 2024

Choose a reason for hiding this comment

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

This code is very very very very Old (~2020), and it is very likely that things were much more unreliable back then. I think this came from this PR:

https://github.com/Expensify/App/pull/339/files

And have been modified a few times after, for example here: https://github.com/Expensify/App/pull/1075/files#r548053786

I think this can be tested by:

  1. accountA is offline and has never chatted with accountB before
  2. accountB creates a DM with accountA and sends a message. accountA misses the push event
  3. accountA goes online
  4. accountB sends another message

That way, when we push the last message sent by accountB in step 4, accountA could have been missing the report, but that is not the case anymore because accountA got the report in step 3 because of "reliable updates".

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree with you @aldo-expensify that the app is more reliable. I think this code is basically here for the case you have laid out i.e. it was possible to get a pusher update for a report that you didn't have locally yet. And in that case, we would fetch it.

cc @tgolen to get more eyes on this one just in case he can think of something we are not seeing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Huh... Good to see this code is no longer necessary! I agree with both of you and the assumptions.

@aldo-expensify aldo-expensify marked this pull request as ready for review January 22, 2024 20:02
@aldo-expensify aldo-expensify requested a review from a team as a code owner January 22, 2024 20:02
@melvin-bot melvin-bot bot requested review from Ollyws and removed request for a team January 22, 2024 20:02
Copy link

melvin-bot bot commented Jan 22, 2024

@Ollyws 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]

@aldo-expensify
Copy link
Contributor Author

cc @MonilBhavsar @marcaaron

@MonilBhavsar
Copy link
Contributor

Looks good! seems like testing steps will cover everything

marcaaron
marcaaron previously approved these changes Jan 24, 2024
@Ollyws
Copy link
Contributor

Ollyws commented Jan 24, 2024

Testing this today.

@Ollyws
Copy link
Contributor

Ollyws commented Jan 24, 2024

Something I've noticed (which is happening on staging too) is that a new chat recieved while offline will not show up in the LHN. This somewhat impedes the given testing steps:

Screen.Recording.2024-01-24.at.12.09.41.mov

@aldo-expensify
Copy link
Contributor Author

Something I've noticed (which is happening on staging too) is that a new chat recieved while offline will not show up in the LHN.

hmm, this didn't happen when I tested in dev, but I never tested with staging backend. Do you see the missing report and reportActions in the ReconnectApp request?

@Ollyws
Copy link
Contributor

Ollyws commented Jan 25, 2024

@aldo-expensify No Onyx data is returned by ReconnectApp, just:
{ "onyxData": [], "lastUpdateID": "91825978", "previousUpdateID": "91825978", "jsonCode": 200, "requestID": "84afedcb0938dd27-LHR" }
But as you can see in the video the data is there when I open search, it just doesn't appear in the LHN.
It does seem to work fine with an already existing chat so I can test it that way but we might want to update the testing steps.

@aldo-expensify
Copy link
Contributor Author

aldo-expensify commented Jan 25, 2024

@aldo-expensify No Onyx data is returned by ReconnectApp, just: { "onyxData": [], "lastUpdateID": "91825978", "previousUpdateID": "91825978", "jsonCode": 200, "requestID": "84afedcb0938dd27-LHR" }

This is unexpected for me and different from what I was getting while testing in dev. You can HOLD on reviewing for now, I have to fix conflicts anyway and then I'll retest.

Old screenshot from my dev testing, ReconnectApp was getting the report + actions:

Screenshot 2024-01-22 at 10 49 12 AM

@tgolen
Copy link
Contributor

tgolen commented Jan 30, 2024

What's the next step for this PR? I see it has a few conflicts.

@aldo-expensify
Copy link
Contributor Author

What's the next step for this PR? I see it has a few conflicts.

I should test again and see why ReconnectApp is not getting the missing report anymore.

@aldo-expensify
Copy link
Contributor Author

Resolved conflicts and retested. I still get the report and reportActions in ReconnectApp:

image

I also tested in staging and I'm getting the report + reportActions in ReconnectApp:

image

@aldo-expensify
Copy link
Contributor Author

aldo-expensify commented Jan 31, 2024

hmm tested again in staging with gmail.com accounts, and I do get the missing report in ReconnectApp, but the LHN didn't update showing the new report 🤔
Screenshot 2024-01-31 at 3 33 25 PM

In this case the reportID for the DM chat is 2107825736451123

The JSON for that report in Onyx is:

{
    "chatType": "",
    "currency": "USD",
    "description": "",
    "hasOutstandingChildRequest": false,
    "isCancelledIOU": false,
    "isOwnPolicyExpenseChat": false,
    "isPinned": false,
    "isWaitingOnBankAccount": false,
    "lastActorAccountID": 16333716,
    "lastMessageHtml": "",
    "lastMessageText": "sdfsdfsf",
    "lastReadSequenceNumber": 0,
    "lastVisibleActionCreated": "2024-01-31 23:33:01.421",
    "lastVisibleActionLastModified": "2024-01-31 23:32:58.428",
    "managerID": 0,
    "maxSequenceNumber": 1,
    "nonReimbursableTotal": 0,
    "notificationPreference": "hidden",
    "oldPolicyName": "",
    "ownerAccountID": 0,
    "participantAccountIDs": [16333716],
    "policyID": "_FAKE_",
    "reportID": "2107825736451123",
    "reportName": "Chat Report",
    "stateNum": 0,
    "statusNum": 0,
    "submitterPayPalMeAddress": "",
    "total": 0,
    "type": "chat",
    "visibleChatMemberAccountIDs": [],
    "welcomeMessage": "",
    "writeCapability": "all"
}

I'm guessing that maybe the chat is staying hidden because of one of these properties: "notificationPreference": "hidden", or "visibleChatMemberAccountIDs": [],

@aldo-expensify
Copy link
Contributor Author

ahh, I think I know whats happening... There is two onyxUpdates for the same report that are arriving in incorrect order:

image

The update with {notificationPreference: "always"} should have arrived after the update containing the report initial data.

@aldo-expensify
Copy link
Contributor Author

I'm going to make this a DRAFT because I don't think we can merge this until the update ordering problem is solved.

@aldo-expensify aldo-expensify marked this pull request as draft January 31, 2024 23:43
@tgolen
Copy link
Contributor

tgolen commented Mar 25, 2024 via email

@aldo-expensify aldo-expensify marked this pull request as ready for review April 2, 2024 03:05
@aldo-expensify
Copy link
Contributor Author

@Ollyws this is ready for review, the backend changes have been deployed. Can you retest this from scratch please 🙏

@aldo-expensify aldo-expensify requested review from c3024 and removed request for Ollyws April 2, 2024 23:15
@aldo-expensify
Copy link
Contributor Author

@c3024
Copy link
Contributor

c3024 commented Apr 2, 2024

@aldo-expensify

Backend sends a 'deprecated version' error. Clicking on update or refreshing the page does not fix it. 🤔

Installed node-modules afresh and tried again still does not work.

deprecatedVersion.mp4

@c3024
Copy link
Contributor

c3024 commented Apr 3, 2024

Please merge main. The version in package.json in this PR is too old.

I am testing after merging main locally.

@c3024
Copy link
Contributor

c3024 commented Apr 3, 2024

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • 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 included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • 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 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
    • 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 either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • 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 other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • 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 */
    • 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 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(theme.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 the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • 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 reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: Native
reconnectAndroid.mp4
Android: mWeb Chrome
reconnectAndroidChrome.mp4
iOS: Native

test1And3

test2iOS.mp4
iOS: mWeb Safari
reconnectiOSSafari.mp4
MacOS: Chrome / Safari

Test 1

reportCreatedWhileOffline.mp4

Test 2

switchingFromAnonAccount.mp4

Test 3

toggleNetworkWithReportScreenOpen.mp4
MacOS: Desktop
test1And3Desktop.mp4

@aldo-expensify
Copy link
Contributor Author

@c3024 I updated with main now

Copy link
Contributor

@c3024 c3024 left a comment

Choose a reason for hiding this comment

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

LGTM and tests well!

@melvin-bot melvin-bot bot requested a review from cristipaval April 3, 2024 02:37
Copy link

melvin-bot bot commented Apr 3, 2024

@cristipaval 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]

@aldo-expensify
Copy link
Contributor Author

Thanks @c3024!

Merging since Marc approved in the past and Tim already approved too.

@aldo-expensify aldo-expensify merged commit 6463de6 into main Apr 3, 2024
15 checks passed
@aldo-expensify aldo-expensify deleted the aldo_remove-reconnect-report branch April 3, 2024 02:45
@OSBotify
Copy link
Contributor

OSBotify commented Apr 3, 2024

✋ 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

OSBotify commented Apr 8, 2024

🚀 Deployed to production by https://github.com/Julesssss in version: 1.4.60-13 🚀

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

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