Skip to content

Conversation

@staszekscp
Copy link
Contributor

@staszekscp staszekscp commented Apr 25, 2023

Details

Fix for wrong freeze behavior on android web - it introduces wrapper that provides Freeze component to mobile apps (where it is really needed)

Part of navigation rework by Software Mansion

BUG: Web: ANDROID: LHN is reloading when we open any page from the FAB menu.

The problem was caused by the Freeze component - on Android web the the freezing was triggered too early (before screen's transition end). Instead of implementing some hacky solutions I decided to remove the Freeze component from the web flow, because it was causing more problems without giving much perfromance advantage there.

Fixed Issues

Related to #16581 (comment)

Tests

  • Verify that no errors appear in the JS console
  1. Open the app on the mobile web.
  2. Open the Fab menu and click on any menu.
  3. Observe that images/page are reloaded in the background.

Offline tests

QA Steps

  • Verify that no errors appear in the JS console
  1. Open the app on the mobile web.
  2. Open the Fab menu and click on any menu.
  3. Observe that images/page are reloaded in the background.

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 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
    • 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
Mobile Web - Chrome Sorry for the quality
Screen.Recording.2023-04-26.at.21.17.37.2.mov
Mobile Web - Safari
Desktop
iOS
Android

* test flatlist for android

* fix linter

* fix name

* fix not working features

* limit rerenders
@staszekscp staszekscp requested a review from a team as a code owner April 25, 2023 11:22
@melvin-bot melvin-bot bot requested review from neil-marcellini and removed request for a team April 25, 2023 11:22
@MelvinBot
Copy link
Contributor

@neil-marcellini 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]

@neil-marcellini
Copy link
Contributor

@staszekscp please follow our contributing guidelines. Were you hired for an issue with an accepted proposal? If so please include those in the description and re-open the PR.

@staszekscp
Copy link
Contributor Author

cc: Hey @mountiny, could you have a look at that?

@neil-marcellini
Copy link
Contributor

Thanks for linking the related issue and now I see that you're from Software Mansion so I'll reopen this. I was going quickly and thought this was a random PR opened unrelated to an issue.

@mountiny
Copy link
Contributor

@staszekscp thanks! it would be great to add a video too and always try to give more context for the PR :D

Copy link
Contributor

@mountiny mountiny left a comment

Choose a reason for hiding this comment

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

@staszekscp You got some lint issues here again, hopefully we will get rid of this with Prettier and typestript haha but make sure to check if the npm run lint is fine before submitting ready for a review

@mountiny mountiny requested a review from s77rt April 26, 2023 18:27
@mountiny
Copy link
Contributor

@s77rt could you give this one a look sooner than later, thank you very much 🙇

Comment on lines 191 to 194
<Freeze
freeze={shouldFreeze}
placeholder={skeletonPlaceholder}
>
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of putting this in the LHNOptionList and making a platform specific implementation for that entire component, could you please create a SidebarFreeze component that wraps its children in Freeze on all platforms except for web, where it wraps the children in nothing <>?

I think that isolates the platform specific part better. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, will do!

Copy link
Contributor

Choose a reason for hiding this comment

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

That sounds reasonable to me, probably just a preference though. @s77rt what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

I will go thought the files in depth but just a quick response. I assume LHNOptionList is exactly the same and the only difference is Freeze is that right? Then It would be better to isolate that component instead as @neil-marcellini suggested. BUT why not remove the Freeze component, is it really doing something significantly good? It's anti react's life-cycle and we will remove it on navigation reboot anyway.

Copy link
Member

Choose a reason for hiding this comment

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

Just realised this is a part of navigation reboot 😁 I think It was planned to remove Freeze at this point, why we are still using it. Am I missing something here? cc @neil-marcellini @mountiny (and @roryabraham I guess you know about this)

@staszekscp
Copy link
Contributor Author

Sorry @mountiny for the lint issues, I keep forgetting that, because in previous projects I couldn't commit anything without passing a lint check via husky script :P I'll keep that in mind, though, so hopefully I will pass the lint check next time!

@neil-marcellini
Copy link
Contributor

Thanks for the SidebarFreeze update! I think as a general rule we should always keep platform specific components as small as possible.

Please include testing videos as described in the PR author checklist. I'm not able to observe the LHN reloading under the global create menu on main. @parasharrajat is that easy to observe or do we need to add logging or otherwise debug to see if the component is updating or remounting? Also could you please write a couple sentences about the problem and how this fixes it, it's not super clear to me.

I'll let @s77rt take the lead on the reviews and come back after he approves.

@staszekscp
Copy link
Contributor Author

@neil-marcellini It is a bug specific to the navigation rework, that's why it is not possible to notice it on the main :)

@s77rt
Copy link
Member

s77rt commented Apr 26, 2023

@neil-marcellini I still have concerns about the use of Freeze, please check comment #17962 (comment) in case you missed it

Copy link
Member

@s77rt s77rt left a comment

Choose a reason for hiding this comment

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

cc @neil-marcellini

focusedIndex={_.findIndex(optionListItems, (
option => option.toString() === this.props.currentReportId
))}
isLoading={isLoading}
Copy link
Member

Choose a reason for hiding this comment

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

I think this is an outdated change. LHNOptionsList does not accept isLoading prop.

Copy link
Member

Choose a reason for hiding this comment

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

I don't see why the renamed is required here (another outdated change?)

Copy link
Contributor

Choose a reason for hiding this comment

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

This is outdated, there was a web file before

Copy link
Member

Choose a reason for hiding this comment

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

All of this is a workaround. The bug is upstream and it has been reported already a while ago software-mansion/react-freeze#31

Copy link
Contributor

@mountiny mountiny left a comment

Choose a reason for hiding this comment

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

@s77rt I think we want to keep Freeze to limit the number of rerender in the stack. All the navigation will be stack based so if we wont have Freeze around the LHN, it would be rerendering in the background

Copy link
Contributor

Choose a reason for hiding this comment

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

This is outdated, there was a web file before

@mountiny
Copy link
Contributor

@s77rt do you want me to make internal release of this branch for testing or are you fine with emulators?

@s77rt
Copy link
Member

s77rt commented Apr 26, 2023

@mountiny I'm fine with emulators. Unfortunately we will have to discuss some more before moving with this PR

  1. How much performance are we actually gaining by using Freeze, is it that significant?
  2. We have a couple of issues that are on hold in favor of the removal of Freeze, how are we supposed to handle those?

Besides the custom flat list here is a workaround, we have a bug report for that #14125

@mountiny
Copy link
Contributor

mountiny commented Apr 26, 2023

Essenatilly the implementation of the refactor means we will be pushing many reports to the stack, they wont be reused so if you will use app for a long time you will have a lot of pages. I think we need to use the Freeze for ReportScreens at least for now to ensure that those are not being rerendered in the background.

I am sure also we can work with SWM to fix the react-freeze issues, they are maintainers of the library

Also is this really only occurring on Android web or also on other platforms?

@s77rt
Copy link
Member

s77rt commented Apr 26, 2023

@mountiny

@mountiny
Copy link
Contributor

Thanks, I understand that.

I think what we need to do is completely test what will be influenced (performance mainly) if we remove the freeze completely. Especially Android app hopes to get better performance with dropping the use of drawer so we need to be cautious with what will be the performance consequence of these changes.

Could anyone try to some quick performance audit for removing the freeze? at least in terms of FPS?

@mountiny
Copy link
Contributor

Asked in Slack to discuss this https://expensify.slack.com/archives/C01GTK53T8Q/p1682548765642099

@parasharrajat
Copy link
Member

I'm not able to observe the LHN reloading under the global create menu on main. @parasharrajat is that easy to observe or do we need to add logging or otherwise debug to see if the component is updating or remounting?

@neil-marcellini When you follow the steps from #16581 (comment). Notice that avatars will go grey which means they are reloading. I could also see the skeleton loader on chats.

@staszekscp
Copy link
Contributor Author

staszekscp commented Apr 27, 2023

I think in the SidebarLinks we don't need the Freeze component so much, because we will not push more than one SidebarLinks screen on the stack. There shouldn't be a huge amount of updates there either.

On the other hand I think it is worth to keep ReportScreen wrapped in the Freeze component, because there may be multiple chats opened, and their re-renders could cause performance harm, especially on slower devices.

An alternative solution that would work to fix this specific Android web issue is to leave the Freeze component, but add a check to see if the screen transition finished. I haven't tested that, but if you prefer this kind of solution I may check this out.

@mountiny
Copy link
Contributor

So I feel like:

  • if we are going to keep the Freeze for the ReportScreen then there is no benefit in removing it from the Sidebar too

We can work with SWM to fix the react-freeze issues, they are keen to fix anything which is wrong with it

Copy link
Contributor

@mountiny mountiny left a comment

Choose a reason for hiding this comment

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

@parasharrajat @s77rt @staszekscp @neil-marcellini after the rect discussion I think we should be bale to use freeze for the report screen but skip its usage for the sidebar, what do you think?

@s77rt
Copy link
Member

s77rt commented Apr 29, 2023

@mountiny I'm okay with keeping Freeze I'm just questioning how to handle the issues that we assumed will be gone after navigation reboot. However I would still discourage the use of Custom FlatList, I would really prefer to keep a bug than apply a workaround.

@neil-marcellini
Copy link
Contributor

So, is this ready for review again? Please message me on NewDot when it is.

Copy link
Contributor

@mountiny mountiny left a comment

Choose a reason for hiding this comment

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

@s77rt Can you please give this one a review again assuming we will keep the Freeze so we know clearly what we need to address, got a bit lost in the conversation cc @staszekscp thank!

Copy link
Member

@s77rt s77rt left a comment

Choose a reason for hiding this comment

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

One additional change request. And please address the other unresolved comments.

Copy link
Member

Choose a reason for hiding this comment

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

Let remove the CustomFlatList and just use the react-native FlatList

@mountiny
Copy link
Contributor

mountiny commented May 5, 2023

@staszekscp lets follow up on this one next week

@mountiny
Copy link
Contributor

Closing this PR in favour of the final one we have here #19263, the changes should be incorporated there.

@mountiny mountiny closed this May 22, 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.

6 participants