Repository navigation
perf(home): POC of migrating the Home tab to React <Activity> - #100318
Draft
dariusz-biela wants to merge 37 commits into
Draft
dariusz-biela wants to merge 37 commits into
dariusz-biela wants to merge 37 commits into
Conversation
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.
Contributor
|
|
… 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 Report✅ Changes either increased or maintained existing code coverage, great job!
|
… dariusz-biela/perf/screen-activity-home
…riusz-biela/perf/screen-activity-home
…riusz-biela/perf/screen-activity-home
… ended while covered
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-screennonTopScreenBehavioroption from #98575; Home is the first tab to opt in.In the app
In the code
createTabNavigator+BottomTabScreenOptions: the bottom-tab navigator acceptsnonTopScreenBehaviorper tab;bottomTabScreenLayoutWrapperwraps the tab content inScreenActivityWrapperwhen a tab opts into'activity'.HOME_TAB_SCREEN_OPTIONSopts the Home tab in; the other tabs are untouched.ForYouSectionwrites the has-seen flag only once the NVP has loaded,useFreeTrialkeeps the discount across an effect remount, the skia chart canvas survives an Activity hide.ReanimatedModalsurvives an effect remount (open animation runs once per mount, a remount does not report a close).tests/ui/activityHomeEffects/*cover every Home widget under a cover and reveal cycle through the sharedScreenCoverHarness, plusbottomTabScreenLayoutWrapperTest.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.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
SetNameValuePairfor the has-seen flag.Offline tests
QA Steps
Same as tests.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari