Skip to content

perf: Freeze screens and unmount Browser and Transactions screens when unfocused #15246

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

andrepimenta
Copy link
Member

Description

This PR improves the performance of the app by:

  • Suspending all screens that are not visible to the user (using React Freeze)
  • Unmounting completely the Browser and the Transaction screens when they are not active
  • Unmounting all Browser tabs that are not active when using the Browser.

Note: Unmounting the Browser also fixes this Browser issue: https://github.com/MetaMask/mobile-planning/issues/1247

Related issues

Fixes: https://github.com/MetaMask/mobile-planning/issues/1247

Manual testing steps

  1. Go to Browser or Transactions
  2. Leave that screen
  3. Re-enter screen, notice it loads again

Screenshots/Recordings

Before

After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

@andrepimenta andrepimenta added team-mobile-platform Mobile Platform team Run Smoke E2E Requires smoke E2E testing labels May 8, 2025
Copy link
Contributor

github-actions bot commented May 8, 2025

https://bitrise.io/ Bitrise

✅✅✅ pr_smoke_e2e_pipeline passed on Bitrise! ✅✅✅

Commit hash: 988cbe0
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/adc065a8-a7c5-47ac-94dc-63f185456657

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

@andrepimenta andrepimenta added the needs-qa Any New Features that needs a full manual QA prior to being added to a release. label May 8, 2025
@andrepimenta andrepimenta changed the title Freeze screens and unmount Browser and Transactions screens when unfocused perf: Freeze screens and unmount Browser and Transactions screens when unfocused May 8, 2025
Copy link
Contributor

@Cal-L Cal-L left a comment

Choose a reason for hiding this comment

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

Left some comments. Let's also provide some vids on before and after showing that the screens are frozen

@@ -1,5 +1,8 @@
import './shim.js';

import { enableFreeze } from 'react-native-screens';
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're on React Navigation v5, it looks like we also need to enable screens via enableScreens(true) and then passing detachInactiveScreens option to stack / tabs / etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -508,6 +508,7 @@ const HomeTabs = () => {
);
},
rootScreenName: Routes.BROWSER_VIEW,
unmountOnBlur: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Since React Navigation v6 removes this option, let's go with the useIsFocus implementation for now since that will still work once we upgrade to v6 - https://reactnavigation.org/docs/upgrading-from-6.x/#the-unmountonblur-option-is-removed-in-favor-of-poptotoponblur-in-bottom-tab-navigator-and-drawer-navigator

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point Cal.
I like the high order component proposal presented on the docs

function UnmountOnBlur({ children }) {
  const isFocused = useIsFocused();

  if (!isFocused) {
    return null;
  }

  return children;
}

Then we can use it in the layout prop of the screen

<Tab.Screen
  name={Routes.BROWSER.HOME}
  options={options.browser}
  component={BrowserFlow}
  layout={({ children }) => <UnmountOnBlur>{children}</UnmountOnBlur>}
 />

@sethkfman sethkfman added the area-performance Issues relating to slowness of app, cpu usage, and/or blank screens. label May 8, 2025
@Cal-L
Copy link
Contributor

Cal-L commented May 13, 2025

@andrepimenta Let's also check if this breaks deeplink behavior cc @tommasini

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-performance Issues relating to slowness of app, cpu usage, and/or blank screens. needs-qa Any New Features that needs a full manual QA prior to being added to a release. Run Smoke E2E Requires smoke E2E testing team-mobile-platform Mobile Platform team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants