Skip to content

[Due for payment 2025-09-26] [$250] Remove SearchContext from the useOnyx when not needed #70300

Closed

Description

@mountiny

Coming from this proposal

Background

The useOnyx hook (a wrapper around the original useOnyx) is used throughout the app. Inside it, we subscribe to SearchContext so the hook can return data from either the regular Onyx keys or the special SNAPSHOT keys (which are specifically designed for the Reports page).
However, useOnyx hooks that are not used on the Reports page don’t need SearchContext, since they don’t rely on currentSearchHash (which is only used to access the current SNAPSHOT data).

Problem

If SearchContext changes, then every useOnyx in the App will rerender. Such context change will trigger rerenders in screens that are rendered in the history, preloaded screens or modals that live outside of navigation like SearchRouter and can cause massive overhead.

Solution

Avoid useOnyx calls outside the Reports/Search tree from subscribing to SearchContext.

How:
SearchContext provides components with isOnSearch prop that with the help of SearchScopeProvider tells us if the useOnyx is part of Search/index component tree(is on Reports page).

To reduce rerenders, we could:

  • take isOnSearch prop out of SearchContext and put it in SearchScopeProvider , isOnSearch doesn't trigger rerenders as it is a static prop.
  • in useOnyx use the new use API to conditionally listen to SearchContext, that way useOnyx hooks that are part of Search/index component tree(this is static) will access SearchContext that they need and useOnyx hooks that don't need it won't rerender.
const useOnyx: OriginalUseOnyx = <TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(key: TKey, options?: UseOnyxOptions<TKey, TReturnValue>, dependencies?: DependencyList) => {
    const {isOnSearch} = useIsOnSearch();
    let currentSearchHash: number | undefined;
    if (isOnSearch) {
        const {currentSearchHash: searchContextCurrentSearchHash} = use(SearchContext);
        currentSearchHash = searchContextCurrentSearchHash;
    }
... rest of useOnyx hook ...

Benefits
This will provide big boost to scenarios where SearchContext changes, examples(perf measured on iOS simulator):

  1. On Reports page the user changes search type with the search type menu(Submit -> Pay):
  • OLD: total React work: 7234.014ms - ~55 commits
  • NEW: total React work: 5357.51 - 48 commits (25%/1877 ms better)
  1. After fresh log into the app, user enters Reports page and then goes back to Inbox:
  • OLD: total React work: 5992.427ms - ~67 commits
  • NEW: total React work: 4890.688 - 59 commits (18%/1102 ms better)
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021965843867509223663
  • Upwork Job ID: 1965843867509223663
  • Last Price Increase: 2025-09-10
Issue OwnerCurrent Issue Owner: @jliexpensify

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Sep 10, 2025
  2. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Sep 10, 2025
  3. changed the title [-]Remove SearchContext from the useOnyx when not needed[/-] [+][$250] Remove SearchContext from the useOnyx when not needed[/+] on Sep 10, 2025
  4. melvin-bot commented on Sep 10, 2025

    @melvin-bot
  5. melvin-bot commented on Sep 10, 2025

    @melvin-bot

    Triggered auto assignment to @jliexpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

  6. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Sep 10, 2025
  7. melvin-bot commented on Sep 10, 2025

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @Pujan92 (External)

  8. removed
    Help WantedApply this label when an issue is open to proposals by contributors
    on Sep 10, 2025
  9. 7 remaining items

  10. changed the title [-][$250] Remove SearchContext from the useOnyx when not needed[/-] [+][Due for payment 2025-09-26] [$250] Remove SearchContext from the useOnyx when not needed[/+] on Sep 19, 2025
  11. melvin-bot commented on Sep 19, 2025

    @melvin-bot

    Reviewing label has been removed, please complete the "BugZero Checklist".

  12. melvin-bot commented on Sep 19, 2025

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.2.15-15 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2025-09-26. 🎊

    For reference, here are some details about the assignees on this issue:

    • @Pujan92 requires payment through NewDot Manual Requests
    • @SzymczakJ does not require payment (Contractor)
  13. melvin-bot commented on Sep 19, 2025

    @melvin-bot

    @Pujan92 @jliexpensify The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

  14. moved this from CRITICAL to AWAITING DEPLOYMENT in [#whatsnext] #qualityon Sep 22, 2025
  15. melvin-bot commented on Sep 26, 2025

    @melvin-bot

    Payment Summary

    Upwork Job

    • Reviewer: @Pujan92 owed $250 via NewDot
    • Contributor: @SzymczakJ is from an agency-contributor and not due payment

    BugZero Checklist (@jliexpensify)

    • (if NewFeature) I have created a PR for any necessary HelpDot updates, or I confirmed no updates are necessary.
    • I have verified the correct assignees and roles are listed above and updated the necessary manual offers
    • I have verified that there are no duplicate or incorrect contracts on Upwork for this job (https://www.upwork.com/ab/applicants/1965843867509223663/hired)
    • I have verified the PR was not reverted
    • I have applied any discounts due to bugs/regressions introduced by this PR
    • I have paid out the Upwork contracts or cancelled the ones that are incorrect
    • I have verified the payment summary above is correct
  16. Pujan92 commented on Sep 27, 2025

    @Pujan92
    Contributor

    We don't need a checklist here as it was an improvement.

  17. jliexpensify commented on Sep 28, 2025

    @jliexpensify
    Contributor

    Payment Summary

    • C+: @Pujan92 $250 (to be paid via New Expensify requests)
  18. moved this from AWAITING DEPLOYMENT to Done in [#whatsnext] #qualityon Sep 28, 2025
  19. JmillsExpensify commented on Sep 30, 2025

    @JmillsExpensify
    Contributor

    $250 approved for @Pujan92

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

AutoAssignerNewDotQualityUsed to assign quality issues to engineersAwaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions