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

Fix leaving room a room when the split bill with multiple participants #23051

Closed
wants to merge 3 commits into from

Conversation

wildan-m
Copy link
Contributor

@johncschuster , @allroundexperts

Details

Fix leaving a room from multiple devices and fix regression when splitting the bill

Fixed Issues

$ #21518
$ #22964
PROPOSAL: #21518 (comment)

Tests

  1. Open a room on the web and on another device (e.g. Android) using the same account
  2. Click room details and click Leave Room on one of the devices (e.g. web)
  3. The user should leave the room on both devices
  • Verify that no errors appear in the JS console

Offline tests

  1. Open a room on the web and on another device (e.g. Android) using the same account
  2. disconnect the internet on both
  3. Click room details and click Leave Room on one of the devices (e.g. web)
  4. At this point the user should only leave a room in the web version only.
  5. re-connect the internet connection
  6. The user should leave the room on both devices

QA Steps

  1. Open a room on the web and on another device (e.g. Android) using the same account
  2. Click room details and click Leave Room on one of the devices (e.g. web)
  3. The user should leave the room on both devices
  • 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 / Chrome
    • iOS / native
    • iOS / 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 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
    • If we are not using the full Onyx data that we loaded, I've added the proper selector in order to ensure the component only re-renders when the data it is using changes
    • 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(themeColors.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 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 author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
Recording.36.mp4
Mobile Web - Chrome
Recording.35.mp4
Mobile Web - Safari
Recording.40.mp4
Desktop
Recording.40.2.mp4
iOS
Recording.38.mp4
Android
Recording.34.mp4

@wildan-m wildan-m requested a review from a team as a code owner July 18, 2023 01:15
@melvin-bot melvin-bot bot requested review from allroundexperts and removed request for a team July 18, 2023 01:15
@melvin-bot
Copy link

melvin-bot bot commented Jul 18, 2023

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

@wildan-m
Copy link
Contributor Author

wildan-m commented Jul 18, 2023

@allroundexperts I've proposed this PR to fix the regression.

I think we have to scope the logic to only a report that can be left, the additional logic is adapted from here:

if (isUserCreatedPolicyRoom || canLeaveRoom || isThread) {

Please let me know your thoughts

Comment on lines +180 to +193
// We scope it to only reports that can be left.
// The nested "if" is intentional and aimed at improving performance.
const policy = prevProps.policies[`${ONYXKEYS.COLLECTION.POLICY}${prevProps.report.policyID}`];
const isThread = ReportUtils.isChatThread(prevProps.report);
const isUserCreatedPolicyRoom = ReportUtils.isUserCreatedPolicyRoom(prevProps.report);
const canLeaveRoom = ReportUtils.canLeaveRoom(prevProps.report, !_.isEmpty(policy));

if (isUserCreatedPolicyRoom || canLeaveRoom || isThread) {
Navigation.goBack();
Report.navigateToConciergeChat();
// isReportRemoved will prevent <FullPageNotFoundView> showing when navigating
this.setState({isReportRemoved: true});
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

@wildan-m This isn't making full sense to me.

Why can't we replace all this with:

if (prevOnyxReportID && !onyxReportID) {
            Navigation.goBack();
            Report.navigateToConciergeChat();
            // isReportRemoved will prevent <FullPageNotFoundView> showing when navigating
            this.setState({isReportRemoved: true});
            return;
        }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why can't we replace all this with:
if (prevOnyxReportID && !onyxReportID) {

@allroundexperts Known issue using only that check is when we split the bill and re-join the public room right after we leave it. as I described earlier, it's tricky to determine if a report is removed. when we remove a report from device A, then device B will get this response from the pusher

[
  {
    "eventType": "onyxApiUpdate",
    "data": [
      {
        "onyxMethod": "set",
        "key": "report_7794307233155968",
        "value": null
      }
    ]
  }
]

The response will completely remove the props.report and make props.reprot equal to defaultProps.report

Here is the tricky part. props.report.reportID === null or _.isEqual(props.report, defaultProps.report) doesn't always mean a report is removed It can also mean:

  1. User is navigating to another report
  2. Onyx data for that report is not ready

Since we have a massive call of openReport, then the concurrent situation can happen, there is a chance that a openReport call already filled props.report but another concurrent openReport (e.g when loading report actions, or updateing lastReadReport) thinks props.report is not ready and then in componentDidUpdate condition prevOnyxReportID && !onyxReportID will be true.

In summary, since this ReportScreen is being used by other pages other than the room, then unexpected situations can happen.

Why scoping the condition works?
It actually minimizes the unexpected error, currently, we can't leave split bill chat, so our navigateToConcierge will not be executed.

Is there any other solution?

Yes, if we can modify the backend to send this value instead of null then we can exactly determine isReportRemoved condition and remove the remaining onyx data of a report from the front end. CONST.REPORT.STATUS.REMOVED is a new value, since CONST.REPORT.STATUS.CLOSED can also mean that the report is archived but not removed

[
  {
    "eventType": "onyxApiUpdate",
    "data": [
      {
        "onyxMethod": "set",
        "key": "report_7794307233155968",
        value: {
                        reportID: 7794307233155968
                        stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
                        statusNum: CONST.REPORT.STATUS.REMOVED,
          },
      }
    ]
  }
]

Copy link
Contributor

Choose a reason for hiding this comment

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

@wildan-m I'm more inclined with fixing this on the backend. But I think that the backend part is not necessarily a regression. That being said, can you post a video of the bug that arises when using:

if (prevOnyxReportID && !onyxReportID) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@allroundexperts Sure, here is the video

Recording.44.2.mp4
  1. split bill issue
  2. re-join the public room right after leaving it. Notice that the issue not always occurred since openReport call not always executed concurrently

Copy link
Contributor

Choose a reason for hiding this comment

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

For the split bill issue, I think even without our changes, its redirecting to a 404 page which is incorrect in its own. Is that correct / do you agree?

Copy link
Contributor

Choose a reason for hiding this comment

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

That might be a possibility. I'd recommend we bring this conversation to Slack though so we can get more opinions from the team.

Just a heads up that I'll be ooo until Aug 8.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@luacmartins, @allroundexperts seems there is no other suggested solution in Slack. can we proceed with this solution?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not fully satisfied by the solution being proposed here. But at the same time, it looks as if we're short of options. Give me a day or two to think more about this.

Copy link
Contributor

@luacmartins luacmartins Aug 8, 2023

Choose a reason for hiding this comment

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

Thanks for starting the discussion in Slack @wildan-m. Let's see what others say about it. I tagged another member of the team to get the conversation going.

@Nikhil-Vats
Copy link
Contributor

Nikhil-Vats commented Jul 30, 2023

Hey @allroundexperts @wildan-m 👋, I was working on this PR and noticed this issue -

  1. Open two tabs and open preferences in second tab. Switch to offline mode.
  2. On the first tab, enter an invalid email like - a@_.co or a long email like 2f34d2be9bce77da59b2e91f1a2bd25e0b85f2142f34d2be9bce77da59b2e91f1a2bd25e0b85f2142f34d2be9bce77da59b2e91f1a2bd25e0b85f214@gmail.com in offline mode.
  3. Click on "+" icon > Request money in the composer in chat for invalid email you entered.
  4. Go to second tab and switch off offline mode.
  5. Go to first tab, user is redirected to concierge chat.

User should stay on the same chat. User shouldn't be navigated away.
The PR I am working on will close the RHN if there is an error but since user is redirected to conceirge, I am not able to test my PR.

Screen.Recording.2023-07-24.at.1.57.00.AM.mov

I commented out the code from the original PR and this stopped happening. So, do you also plan to fix this in this PR?

From what I investigated onyxReportID here becomes undefined due to which the if block condition becomes true and user is navigated to conceirge chat.

Might require a backend change like you both said.

@wildan-m
Copy link
Contributor Author

@Nikhil-Vats will your activities will cancel/discard report creation when an error occurred? If yes then the redirection issue should be resolved once we can distinguish the type of report removal from the backend.

@allroundexperts, can we proceed with the backend change?

@Nikhil-Vats
Copy link
Contributor

@allroundexperts @wildan-m This is the expected behaviour for the issue I am working on, only RHN should close but the user should stay on the same chat.

Screen.Recording.2023-07-31.at.8.57.32.AM.mov

@Nikhil-Vats
Copy link
Contributor

Hey @allroundexperts @wildan-m, is it okay with you if we revert the changes in the original PR so that we can get unblocked on this PR? You can add those changes back in this PR with the correct fix.

We discussed it here but wanted to confirm with you.

@allroundexperts
Copy link
Contributor

Hey @allroundexperts @wildan-m, is it okay with you if we revert the changes in the original PR so that we can get unblocked on this PR? You can add those changes back in this PR with the correct fix.

We discussed it here but wanted to confirm with you.

That's fine @Nikhil-Vats

@Nikhil-Vats
Copy link
Contributor

Thanks for the quick confirmation @allroundexperts.

@Nikhil-Vats
Copy link
Contributor

@allroundexperts I also wanted to confirm if you are also handling this scenario as per your comment here -

With these steps, currently (without the changes of the PR mentioned), we're showing the user a 404 page which is incorrect as well. After applying the changes, the user is being redirected to concierge. I think both behaviours are incorrect. What should really happen in this case is that the backend should not clear the whole Onyx report. Rather it should just add error fields to the report object. That way, we can show to the user that some error occured.

We want to stay on the same page after the error but since the whole report is cleared, we are redirected to 404 page.

Screen.Recording.2023-08-02.at.21.23.37.mov

Steps -

  1. Go offline via dev tools/turning off wifi.
  2. Enter an invalid email like a@_.co in new chat.
  3. Open any step in request money flow for new chat.
  4. Go back online.

Expected - User should stay on the same page, RHN (request money modal) should close and error is shown.
Actual - User is redirected to 404 page.

This happens on desktop app very frequently, on other platforms this happens sometimes and after a delay.

If yes, we will put this issue on hold for this fix.

@wildan-m
Copy link
Contributor Author

wildan-m commented Aug 2, 2023

@allroundexperts I also wanted to confirm if you are also handling this scenario as per your comment #22964 (comment) -

@Nikhil-Vats @allroundexperts It seems that 404 has a different root cause and will not be directly fixed here, what we will fix is regression related to navigating to the concierge chat which should only apply after the user leaves a room. (not caused by report creation cancelation)

@wildan-m
Copy link
Contributor Author

Moving here: #24407

@wildan-m wildan-m closed this Aug 11, 2023
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.

4 participants