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

Always listen for Network Connection for Offline Indictor #11672

Merged
merged 8 commits into from
Oct 17, 2022

Conversation

grgia
Copy link
Contributor

@grgia grgia commented Oct 7, 2022

Details

The offline indicator stopped working after signout/signing back in.
Also fixes the resulting issue that signing off while offline would require a refresh in order to sign back on.
This fix means that the App will always listen for network connection. More discussion in the linked issue!

Fixed Issues

$ #10524

Tests

  • Verify that no errors appear in the JS console

Tests performed locally:

  1. Sign into an account
  2. Sign out of the account
  3. Sign back into the account
  4. Go to the dev console Network tab and set network conditions to Offline
  5. Ensure the offline indicator shows up
  6. Set network conditions back to No Throttling
  7. Ensure the offline indicator disappears

PR Review Checklist

PR Author Checklist

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 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 included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed 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 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 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 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
  • 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 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.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

PR Reviewer Checklist

The reviewer will copy/paste it into a new comment and complete it after the author checklist is completed

  • 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 verified tests pass on all platforms & I tested again on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • 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 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 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 */
    • 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

QA Steps

  • Verify that no errors appear in the JS console
  1. Sign into an account
  2. Sign out of the account
  3. Sign back into the account
  4. Go to the dev console Network tab and set network conditions to Offline
  5. Ensure the offline indicator shows up
  6. Set network conditions back to No Throttling
  7. Ensure the offline indicator disappears

Screenshots

Web

Screen Shot 2022-10-07 at 10 16 52 AM

Screen Shot 2022-10-07 at 10 16 45 AM

Mobile Web - Chrome

Screen Shot 2022-10-07 at 10 38 25 AM

Screen Shot 2022-10-07 at 10 38 06 AM

Mobile Web - Safari

Screen Shot 2022-10-11 at 12 11 50 PM

note: used force offline, so ignore iphone wifi icon

Desktop

Screen Shot 2022-10-07 at 10 23 10 AM

Screen Shot 2022-10-07 at 10 22 53 AM

iOS

Screen Shot 2022-10-11 at 12 09 05 PM

note: used force offline, so ignore iphone wifi icon

Android

Screen Shot 2022-10-07 at 10 36 59 AM

Screen Shot 2022-10-07 at 10 36 26 AM

@grgia grgia requested a review from a team as a code owner October 7, 2022 17:45
@grgia grgia self-assigned this Oct 7, 2022
@melvin-bot melvin-bot bot requested review from MonilBhavsar and removed request for a team October 7, 2022 17:45
Copy link
Contributor

@MonilBhavsar MonilBhavsar left a comment

Choose a reason for hiding this comment

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

Solution makes sense to me, but should we update subscribeToNetInfo() method to not attach listener if one already exists? or clear previous one? Looks like this was the only place where we're clearing the listeners.

@grgia
Copy link
Contributor Author

grgia commented Oct 10, 2022

Solution makes sense to me, but should we update subscribeToNetInfo() method to not attach listener if one already exists? or clear previous one? Looks like this was the only place where we're clearing the listeners.

@MonilBhavsar That's a good point and I think I agree- but since we plan on always listening for network info whether or not the user is signed on, I'm not sure when we should clear them. They're currently initialized here when the App is built, and I thought that event listeners were removed when an App is killed, so is there a way for duplicate listeners to be created with this set up?

@grgia
Copy link
Contributor Author

grgia commented Oct 10, 2022

@yuwenmemon @marcaaron Tagging since you worked on this flow in the past, do you have any suggestions for a better way to subscribe/clear the network info listeners for the offline indicator outside of signing off?

Copy link
Contributor

@neil-marcellini neil-marcellini left a comment

Choose a reason for hiding this comment

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

Looks good to me! I'll approve once you complete the checklist. suggestion: keep your PRs as drafts until you complete the checklist.

@grgia grgia marked this pull request as draft October 10, 2022 18:30
@grgia grgia marked this pull request as ready for review October 11, 2022 19:13
@marcaaron
Copy link
Contributor

marcaaron commented Oct 11, 2022

If we don't have any reason to disconnect the subscribers can we also remove the methods here:

/**
* Tear down the event listeners when we are finished with them.
*/
function stopListeningForReconnect() {
Log.info('[NetworkConnection] stopListeningForReconnect called');
if (unsubscribeFromNetInfo) {
unsubscribeFromNetInfo();
unsubscribeFromNetInfo = undefined;
}
if (unsubscribeFromAppState) {
unsubscribeFromAppState();
unsubscribeFromAppState = undefined;
}
}

@marcaaron
Copy link
Contributor

marcaaron commented Oct 11, 2022

event listeners were removed when an App is killed

This is true since the JS is not running anymore and would need to be evaluated again when the user reopens the app. I think the same would be true if they are returning from background, but probably something we can test.

is there a way for duplicate listeners to be created with this set up

I don't think so, but it should be testable. Definitely not possible on web/desktop - not 100% sure about native or if we could see a memory leak there, but guessing the answer is no.

@grgia grgia marked this pull request as draft October 12, 2022 22:07
@grgia grgia force-pushed the georgia-offline-bug branch from 806098e to eab30a1 Compare October 12, 2022 22:43
Copy link
Contributor

@neil-marcellini neil-marcellini left a comment

Choose a reason for hiding this comment

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

You have some lint errors in NetworkConnection.js due to unused variable / exports. All you need to do is delete them.

@grgia grgia marked this pull request as ready for review October 13, 2022 17:25
@grgia grgia requested a review from neil-marcellini October 13, 2022 17:25
@grgia
Copy link
Contributor Author

grgia commented Oct 13, 2022

@AndrewGable do you have any idea why the PR review checklist test isn't passing here?

@AndrewGable
Copy link
Contributor

It might have changed since you opened the PR, can you double check you are using the latest one?

@neil-marcellini
Copy link
Contributor

👀 I'm reviewing again and I'll work on the reviewer checklist. For some reason it's not part of the checks but it should be done anyways.

@neil-marcellini
Copy link
Contributor

QA Steps

  • Verify that no errors appear in the JS console
  1. Sign into an account
  2. Sign out of the account
  3. Sign back into the account
  4. Go to the dev console Network tab and set network conditions to Offline
  5. Ensure the offline indicator shows up
  6. Set network conditions back to No Throttling
  7. Ensure the offline indicator disappears

I think it would be good to add some screenshots for steps 4-6, because I'm not sure if QA knows how to open dev tools and change the Network conditions. They might know, but it's best to spell it out.

@neil-marcellini
Copy link
Contributor

Let's also make the QA steps for Web and Desktop only because as far as I know those are the only platforms where you can open devtools (use command + option + i).

@neil-marcellini
Copy link
Contributor

PR 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:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • 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 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 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 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Testing videos:

Web
https://user-images.githubusercontent.com/26260477/195908748-9221d8db-7487-4657-b406-0e1255e050ba.mov

iOS

ios-offline.mp4

Safari iOS

safari-offline.mp4

Desktop

desktop-offline.mov

Android

android-offline.mov

Android Chrome

chrome-offline.mov

Copy link
Contributor

@neil-marcellini neil-marcellini left a comment

Choose a reason for hiding this comment

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

Good to go! I used force offline to test on iOS, but it's really kind of irrelevant to the changes here. At least it proved that iOS and Safari platforms still run properly.

@neil-marcellini neil-marcellini merged commit fd4edd4 into main Oct 17, 2022
@neil-marcellini neil-marcellini deleted the georgia-offline-bug branch October 17, 2022 23:35
@OSBotify
Copy link
Contributor

✋ 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

🚀 Deployed to staging by @neil-marcellini in version: 1.2.18-0 🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by @neil-marcellini in version: 1.2.18-0 🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to production by @chiragsalian in version: 1.2.18-10 🚀

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.

6 participants