-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
Problem
When a user opens the "Create expense" flow (via global + button), the mount path subscribes to ONYXKEYS.COLLECTION.TRANSACTION_DRAFT as a full collection in 8+ components/hooks. Each of these subscriptions forces Onyx to iterate the entire draft transactions collection and triggers re-renders whenever any draft transaction changes — even though most of these components only need a single draft transaction (or none at all). Additional unnecessary subscriptions (full transaction violations collection, policy/report lookups that always return false during creation, redundant subscriptions from HOC wrappers) compound the problem, slowing down the ManualOpenCreateExpense metric.
Solution
Remove or narrow the Onyx subscriptions that fire during the expense creation mount path:
- Remove
useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT)full-collection subscriptions from 8 components/hooks (BaseFloatingCameraButton,EmployeeTestDriveModal,useReceiptScanDrop,SubmitDetailsPage,useAttachmentUploadValidation,FloatingActionButtonAndPopover,DistanceRequestStartPage,IOURequestStartPage), since the underlying functions (initMoneyRequest,clearMoneyRequest,startMoneyRequest) already read from the module-level Onyx cache - In
useShowNotFoundPageInIOUStep, skip the policy/iouReport Onyx subscriptions when not editing (always returns false during CREATE) - In
IOURequestStepAmount, replace theuseOnyx(COLLECTION.TRANSACTION_VIOLATIONS)collection subscription with an imperativegetAllTransactionViolations()call at usage time; use an IDs-only selector instead of fetching full Transaction objects; skipuseDuplicateTransactionsAndViolationscollection scanning when not editing - In
IOURequestStartPage, export and useIOURequestStepAmountWithTransactionOnlyto bypass the redundantwithWritableReportOrNotFoundHOC, eliminating 5 duplicate subscriptions - In
AccessOrNotFoundWrapper, accept an optionalreportprop to skip a duplicate Onyx subscription when the parent already provides the report