Skip to content

perf(home): POC of migrating the Home tab to React <Activity> - #100318

Draft
dariusz-biela wants to merge 37 commits into
Expensify:mainfrom
software-mansion-labs:dariusz-biela/perf/screen-activity-home
Draft

dariusz-biela wants to merge 37 commits into
Expensify:mainfrom
software-mansion-labs:dariusz-biela/perf/screen-activity-home

Conversation

@dariusz-biela

Copy link
Copy Markdown
Contributor

Explanation of Change

Proof of concept of migrating the Home tab to React <Activity>: while another tab or route covers Home, its subtree is hidden instead of staying live, so its Onyx subscriptions and effects stop running until the tab is revealed. Built on the per-screen nonTopScreenBehavior option from #98575; Home is the first tab to opt in.

In the app

  • Home stops re-rendering in the background while the user is on Inbox, Reports, Workspaces or Account (reconnect storms, report switching, edits on Search).
  • Returning to Home re-runs the widgets' effects, so the widgets refresh on reveal (same as a tab focus does today).
  • Charts, the for-you flag, the free trial discount and the web modals behave the same across a hide and reveal.

In the code

  • createTabNavigator + BottomTabScreenOptions: the bottom-tab navigator accepts nonTopScreenBehavior per tab; bottomTabScreenLayoutWrapper wraps the tab content in ScreenActivityWrapper when a tab opts into 'activity'. HOME_TAB_SCREEN_OPTIONS opts the Home tab in; the other tabs are untouched.
  • Home widgets made hide/reveal safe: ForYouSection writes the has-seen flag only once the NVP has loaded, useFreeTrial keeps the discount across an effect remount, the skia chart canvas survives an Activity hide.
  • Web ReanimatedModal survives an effect remount (open animation runs once per mount, a remount does not report a close).
  • Tests: tests/ui/activityHomeEffects/* cover every Home widget under a cover and reveal cycle through the shared ScreenCoverHarness, plus bottomTabScreenLayoutWrapperTest.

Performance results (web, 5 iterations per scenario)

A/B against the merge-base on main, Playwright + React DevTools profiler, headless Chromium on the dev server, mean of 5 iterations after 1 discarded warm-up. INP is the Interaction to Next Paint of the measured window; the reconnect scenarios have no user input, hence n/a. The report-switching scenarios were measured in both orders because their work count drifts over time.

Scenario Render ms (main / activity) Component renders (main / activity) INP ms (main / activity)
Home covered by Inbox, come back online 356 / 334 (-6%) 9105 / 8316 (-9%) n/a
Home never mounted, come back online (control) 320 / 314 (-2%) 8403 / 7902 (-6%) n/a
Home revealed after a trip to Search 155 / 243 (+57%) 7354 / 9473 (+29%) 131 / 150 (+15%)
Home covered by Inbox, 20 report switches (main first) 1586 / 1437 (-9%) 56207 / 51090 (-9%) 125 / 131 (+5%)
Home covered by Inbox, 20 report switches (activity first) 1386 / 1377 (-1%) 48375 / 48784 (+1%) 138 / 131 (-5%)
Home never mounted, 20 report switches (control, main first) 1827 / 1336 (-27%) 55953 / 48266 (-14%) 149 / 130 (-13%)
Home never mounted, 20 report switches (control, activity first) 1358 / 1154 (-15%) 48809 / 43964 (-10%) 136 / 120 (-12%)

Home subtree renders in the measured window (first profile per scenario), main vs this branch: covered reconnect 662 / 0, covered report switching 481 / 0 and 337 / 0, reveal 824 / 80. Deferred (Idle) commits on this branch contained no Home fibers in any scenario.

Fixed Issues

$ #98254
PROPOSAL: N/A

Tests

  1. Sign in on web, open the Home tab and wait for the widgets to load. Switch to the Inbox tab, open a report, then toggle the network off and on in DevTools. Verify that the Inbox recovers normally and that no Home widget flashes or reloads behind it.
  2. Go back to the Home tab. Verify that every widget (For you, Time sensitive, Your spend, Insights, Recently added, Free trial when applicable) shows the same content as before it was covered and that the spend chart is still drawn and interactive.
  3. From Home, open the Search tab, edit a merchant inline on the Expenses table, then return to Home. Verify that Recently added and Your spend reflect the edit.
  4. On Home with a to-do visible, cover and reveal the tab several times. Verify that the For you section stays visible and that the network tab shows no repeated SetNameValuePair for the has-seen flag.
  5. On a report, open a message context menu (web modal), switch to Home and back. Verify that the menu can be opened again and closes on a single dismiss.
  • Verify that no errors appear in the JS console

Offline tests

  1. Load Home, go offline, switch to Inbox and back to Home. Verify that the widgets render their last data with the offline indicator and that no request is queued by the reveal.
  2. Come back online while on Inbox. Verify that the Home widgets refresh once the tab is revealed.

QA Steps

Same as tests.

  • 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
  • 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 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 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)
  • 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)
  • 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 new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • 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.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • 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

WebGLRenderer.dispose() loses the canvas's WebGL context on every layout-effect
cleanup, but an <Activity> hide (and StrictMode's DEV double-invoke) re-runs the
effects on the same element, where a lost context is permanent - the reveal can
never create a surface again and the hidden backdrop shows a white block where
the chart was.

Patch skia to defer the release by one microtask and lose the context only once
the canvas has really left the document, mirroring upstream PR
wcandillon/react-native-skia#4027 (issue Expensify#3976): a hidden screen keeps its context
and its last presented frame, the reveal reuses the live context like the resize
path always has, and a real unmount still releases the context slot
deterministically.
The web modal container drives its open animation from a shared value and
latched the start behind another shared value. A remount cancels the
animation but not the latch, so the second mount bailed out, the container
stayed at progress 0 and the open callback never ran. The start now reads
its callback through a ref, which keeps the effect dependencies stable and
starts the animation once per mount instead.

A remount also replays the exit animation for a modal that is still open,
and that replay reported a close, which put the state machine back into a
state it could never leave and left an invisible backdrop swallowing every
click. The close callback now ignores a report that arrives while the modal
is still meant to be visible.
The open effect kept animationInTiming as a dependency, and Modal/index.tsx
feeds that prop from getWebModalAnimation(type, isSmallScreenWidth). Crossing
the small-screen breakpoint with a RIGHT_DOCKED or CENTERED modal open re-ran
the effect on an already-open container and re-fired the open callback, and an
Activity reveal or StrictMode did the same. The timing is now read through a
ref like the callback, so the effect depends only on the shared value and the
comment describes what the code actually does.
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

⚠️ This PR is possibly changing native code and/or updating libraries, it may cause problems with HybridApp. Please check if any patch updates are required in the HybridApp repo and run an AdHoc build to verify that HybridApp will not break. Ask Contributor Plus for help if you are not sure how to handle this. ⚠️

… listener

The composer tracks whether the report list is scrolling in a ref that only the
SCROLLING listener writes. An Activity hide removes that listener, so a hide
taken while the list was scrolling left the flag stuck on: after the reveal the
wheel handler kept cancelling every wheel event over the composer and the user
could no longer scroll it. The cleanup now resets the flag along with the
listener it belongs to. The deps are empty, so outside the opt-in that cleanup
only runs at unmount, where the ref dies anyway.
The effect that restores the composer scroll after a full size toggle means
"when isComposerFullSize changed, restore", but an Activity reveal runs it
again with the prop unchanged and overwrites wherever the user had scrolled the
input. It now records the value it last acted on and returns early when it has
not moved. The ref starts at the current prop, which is equivalent on a real
mount because prevScroll and prevHeight are both undefined there.
The markdown input scrolls itself to the bottom whenever the value changes with
the caret at the end. An Activity reveal re-runs that effect with the same value
and the same caret, so a user who had scrolled up inside a long draft lost that
position on every uncover. The effect now keys on the value and caret it last
scrolled for and returns early when neither moved, which leaves the first mount
and every real edit unchanged.
Both scroll effects are now guarded against re-running with unchanged inputs, so
these tests hold the other half of each guard: a real full size toggle still
restores the offset and a real edit with the caret at the end still scrolls to
the end. The textarea helper gives the web Composer a DOM node with drivable
scroll metrics, which jsdom cannot provide on its own.
The Home tab gained a text input after the migration audit was written, so
nothing covered the composer chain. This suite drives ConciergePromptBox through
ScreenCoverHarness and pins the draft flush, the value and caret, the focus, the
max length warning, the "+" menu, the scroll offset, the missed SCROLLING event
and the DOM listener counts. It passes in both cover modes, so it also records
where Activity matches today. The component gains the testIDs the suite targets.
MarkdownTextInput registered its parser worklet from a useMemo and only
unregistered it from an effect cleanup. Every remount of the effects alone,
which is what StrictMode does after mount and what a hidden <Activity> does on
every hide, erased the entry from the C++ registry while the decorator view
kept the same parserId, and the re-run re-armed the cleanup without registering
anything. The next parse looks that id up with std::unordered_map::at, so iOS
catches the out_of_range and returns no ranges and Android lets it out of the
JNI call: the Concierge composer on Home stops formatting markdown for good.

The patch registers in the effect body, unregisters the id that body took in
its cleanup, and pushes the new id to the decorator through state. The first
registration stays in the first render, because the effect runs after the first
paint and the view must never carry an id the registry cannot resolve.
Every icon on Android renders through ImageSVG, whose mount effect cleanup
called expo-image's process-wide Image.clearMemoryCache(). It was added as a
precaution alongside the cachePolicy="memory" fix for Expensify#34881, but it empties
the cache the fix relies on, and it fires for a list row being recycled or a
popover closing, avatars and receipts included. Under Activity it also fires on
every hide of Home, once per mounted icon, exactly while the covering RHP is
loading its own icons, and the images it claims to free are still on screen.
Glide trims the cache under memory pressure on its own, so the flush is gone.
useAppState mirrored AppState into component state from a subscription set up
in an effect. A hidden screen holds no subscription, so a change that lands
while an RHP or a modal covers Home is lost, and the reveal only resubscribed:
the hook went on reporting a foreground the app had left, and the Lottie
animation Home renders through the insights section kept animating instead of
falling back to a plain view.

The status now comes from useSyncExternalStore, which re-reads it on every
render and on every resubscribe, so there is no mirror to go stale. The
optional change callback keeps its own subscription, so it still fires only for
events that actually happened. One frozen object per status keeps the returned
identity stable for consumers.
…ction

Selecting a popover menu item that hands focus over takes a lease on the
background input focus suppression and asks for the modal to close on the next
commit. Both are meant to survive the transition the selection starts, which is
the very transition that covers Home, so a hide must not drop them. It did: the
unmount-only cleanup released the lease with no body to re-acquire it, and the
reveal ran the pending close again over a request still held in state, closing a
second time and re-running the item's callback.

The cleanup now records that it held the lease and the body re-acquires it, and
the close effect remembers the request it already closed for.
The selection effect exists to scroll the caret back into view when the
composer leaves full size, which is why it depends on that size alone and not
on the selection. An effect remount repeats the move for a toggle that never
happened, so revealing Home scrolled the Concierge composer back to the caret
the user had scrolled away from. The size the effect last acted on is now kept
in a ref, which a cover leaves alone, and a real toggle still moves the caret.
… hidden

The hook exists because Android leaves an EditText focused when the keyboard
goes away on its own. A hidden screen holds no keyboard listener, so the
dismissal that comes with navigating to an RHP never reaches the Concierge
composer, and the reveal only resubscribes: the composer comes back focused
with no keyboard on screen, which is the state the hook was written to prevent.

The effect body now reads the keyboard back from KeyboardController and blurs
an input it already saw the keyboard open for, so a first mount that puts the
focus in the input straight away is untouched.
DevSettings has no API for removing a menu item and the native menu keeps every
item it is given, so this registration cannot be paired with a cleanup. Adding
it per effect mount grew the dev menu by one duplicate row per cover and reveal
of any screen that renders a ScreenWrapper, Home included.
The announcement belongs to the message and not to the mount, and the ref that
holds the last announced message survives a cover, so a reveal must not read an
unchanged form error out to VoiceOver again. This was safe as written; the test
keeps it that way.
The unmount-only cleanup reset isVisibleState and isContainerOpen next to
ending the tracked transition. At a real unmount React discards both updates,
so the lines only ever did something when an effect teardown was not an
unmount: covering the Home tab unmounted the container of a modal the user
still sees, and the reveal took the open branch again, replaying the open
animation and onModalWillShow for a modal nobody reopened.
The single effect announced an open or a close on every run, and the run it
gets on a reveal carries the same isVisible it had before the cover. Home
mounts this popover whether or not it is open, so revealing the tab replayed
a full close into shared modal state, consuming the pending close callback of
whichever modal was waiting for it, and replayed onModalShow for one that was
open. The announcement now follows a change of isVisible, while the close
handler is still registered on every run because its cleanup drops it.
…ttaches

The hook compares the previous root-history snapshot with the current one to
tell a browser Back from its own dispatch. Covering the screen removes the
guard entry and the store subscription, so a reveal compared a pre-cover
snapshot against a history that had moved, reduced that into a Back press and
closed a modal the user left open. The open branch now reads the live snapshot
key, which is a no-op whenever the subscription was live throughout.
BaseModal runs its close bookkeeping and clears its covering entry from an
unmount-only cleanup, and an Activity hide runs that cleanup on a modal that
is still painted. Neither can be fixed where they are written, so the two
expectations record today's behavior per cover mode and name the defect.
@codecov

codecov Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/components/Lottie/index.tsx 95.08% <100.00%> (+13.72%) ⬆️
...ents/Modal/ReanimatedModal/Container/index.web.tsx 95.83% <100.00%> (+95.83%) ⬆️
src/hooks/useCachedImageSource.ts 96.07% <100.00%> (+96.07%) ⬆️
src/hooks/useFilesValidation.tsx 95.03% <100.00%> (+70.19%) ⬆️
src/hooks/useLazyAsset.ts 85.71% <100.00%> (+14.71%) ⬆️
src/hooks/useLocalReceiptThumbnail.ts 92.00% <100.00%> (+13.42%) ⬆️
...AppNavigator/Navigators/HOME_TAB_SCREEN_OPTIONS.ts 100.00% <100.00%> (ø)
...on/AppNavigator/Navigators/TabNavigator.native.tsx 96.87% <100.00%> (ø)
...tion/AppNavigator/Navigators/createTabNavigator.ts 100.00% <100.00%> (ø)
...avigation/PlatformStackNavigation/ScreenLayout.tsx 86.95% <100.00%> (+2.74%) ⬆️
... and 4 more
... and 411 files with indirect coverage changes

Patch 001 re-registers the parser worklet from a layout effect instead of a
passive one. React flushes the state update that carries the new id before it
yields, so the commit that revealed the screen (or changed the parser identity)
and the commit with the replacement id reach the mounting layer in the same
task and collapse into one native transaction, instead of leaving the decorator
view on the erased id for a whole frame.

Patch 002 makes getMarkdownWorklet resolve ids with find and return nullptr for
an unknown one, and both native parsers return no ranges for it. A parse that
still lands in the remaining sub-frame gap formats nothing and no longer pays
for std::out_of_range unwinding (or its fbjni translation on Android); the
ranges are cached per (text, parserId), so the replacement id re-parses the same
text as soon as the view receives it.

details.md now links the PR introducing the patches, and the registration test
pins that a parser identity change moves the decorator to one live id.

This branch has not been deployed

No deployments
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.

1 participant