Skip to content

[Due for payment 2026-03-30] Reduce Onyx subscription overhead in the expense creation flow #84925

@marcaaron

Description

@marcaaron

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 the useOnyx(COLLECTION.TRANSACTION_VIOLATIONS) collection subscription with an imperative getAllTransactionViolations() call at usage time; use an IDs-only selector instead of fetching full Transaction objects; skip useDuplicateTransactionsAndViolations collection scanning when not editing
  • In IOURequestStartPage, export and use IOURequestStepAmountWithTransactionOnly to bypass the redundant withWritableReportOrNotFound HOC, eliminating 5 duplicate subscriptions
  • In AccessOrNotFoundWrapper, accept an optional report prop to skip a duplicate Onyx subscription when the parent already provides the report
Issue OwnerCurrent Issue Owner: @BartekObudzinski

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions