Skip to content

[Due for payment 2026-12-08] [$175] perf: Keep SearchQueryContext stable when an unrelated policy changes #107758

Open

Description

@mountiny

Problem

The Spend page re-renders on every policy update, even when nothing it shows changed. SearchQueryProvider subscribes to the whole policy_ collection to compute one flag, shouldShowExpensifyCard, so any policy write rebuilds the SearchQueryContext value and re-renders every consumer. SearchTypeMenuNarrow also builds its tabs from menu sections that are recomputed on every policy, card or report write, so every tab re-renders.

Solution

SearchQueryProvider now selects only the shouldShowExpensifyCard boolean, so unrelated policy writes no longer change the context value. SearchTypeMenuNarrow keeps the previous tabs and queries while they are deeply equal, and builds the saved search overflow menu only for the search being edited. A new useStableReference(value, isEqual) hook backs this, and useStableObjectReference and useStableArrayReference now wrap it.

PR

#107734

Issue OwnerCurrent Issue Owner: @jayeshmangwani
Upwork Automation - Do Not Edit

Activity

  1. added
    Reviewing
    Daily
    Bug
    on Nov 23, 2026
  2. added
    External
    on Nov 23, 2026
  3. expensify-chore-bot commented on Nov 23, 2026

    @expensify-chore-bot

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

  4. changed the title [-]perf: Keep SearchQueryContext stable when an unrelated policy changes[/-] [+][$175] perf: Keep SearchQueryContext stable when an unrelated policy changes[/+] on Nov 23, 2026
  5. expensify-chore-bot commented on Nov 23, 2026

    @expensify-chore-bot
  6. MelvinBot commented on Nov 23, 2026

    @MelvinBot
    Contributor

    Proposal

    Confidence: Medium — source evidence supports the reported mechanism; render counts and timings were not independently reproduced.

    What is the root cause of that problem?

    Two independent paths propagate reference changes even when the displayed search data is unchanged:

    1. Search context: The provider subscribes to the entire policy collection but uses it only to derive shouldShowExpensifyCard. Unrelated policy writes invalidate downstream derivations and the context consumed by search components.
    2. Narrow search menu: Rebuilt tab/query containers and overflow-menu-dependent callbacks prevent reuse of the tab subtree.
    Code evidence and scope
    • The original subscription and context construction are in SearchQueryProvider.tsx:71–105. Consumers use ordinary context subscription, including transaction rows.
    • The original menu constructs fresh containers and callbacks in SearchTypeMenuNarrow.tsx:106–252.
    • This concerns reference stability under React Compiler—not simply the presence of object literals.
    • The provider optimization applies to web generally. The narrow-menu optimization applies to narrow web layouts, not the wide sidebar.
    • This does not eliminate every policy-driven render: useCardFeedsForDisplay.ts:105–130 still subscribes to policies.

    What changes do you think we should make in order to solve the problem?

    The existing Keep SearchQueryContext stable PR addresses both paths appropriately:

    • Select the visibility boolean at the subscription boundary.
    • Retain equivalent tabs and navigation queries, so unchanged menus remain stable without retaining outdated queries.
    • Construct overflow actions only for the selected saved search.

    Continue with that PR rather than opening a duplicate. Before acceptance, verify unrelated writes preserve context/tab identity while meaningful changes still update correctly.

    Validation and remaining gaps

    The provider regression tests cover unchanged context identity after a workspace rename and updated reconciliation queries after enabling cards.

    Remaining useful coverage:

    • Disabling cards or removing the last qualifying workspace.
    • Updating a saved search’s query without changing its visible title.
    • Unrelated writes versus genuine tab changes in the narrow menu, including overflow actions.

    An alternative explanation—remaining policy subscriptions—does explain residual renders, but does not invalidate the targeted context stabilization. Backend logs are unnecessary for this client-side mechanism. Tests and browser profiling were not independently run.

    What alternative solutions did you explore? (Optional)

    Stabilizing only the tabs would leave query/callback churn unresolved. Suppressing all policy updates would incorrectly hide legitimate visibility changes.

    Related work: Keep to-do search data stable on unrelated writes and Keep cached Onyx arrays when re-sent data is unchanged. These are related performance efforts, not confirmed duplicates.


    Next Steps for Contributor+ team:
    To accept: Review the existing PR; no additional implementation PR is needed.
    To refine: @MelvinBot <your feedback>
    To reject: Explain why you are rejecting Melvin’s proposal.


    view run

  7. added
    Weekly
    and removed
    Daily
    on Nov 24, 2026
  8. moved this from CRITICAL to AWAITING DEPLOYMENT in [#whatsnext] #qualityon Nov 30, 2026
  9. added
    Daily
    and removed
    Reviewing
    Weekly
    on Dec 1, 2026
  10. changed the title [-][$175] perf: Keep SearchQueryContext stable when an unrelated policy changes[/-] [+][Due for payment 2026-12-08] [$175] perf: Keep SearchQueryContext stable when an unrelated policy changes[/+] on Dec 1, 2026
  11. melvin-bot commented on Dec 1, 2026

    @melvin-bot

    @jayeshmangwani

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.5.55-6 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 2026-12-08. 🎊

    The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the Contributor+ 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]. If no checklist is needed for this issue, you can click: [no checklist button]

  12. jayeshmangwani commented on Dec 2, 2026

    @jayeshmangwani
    Contributor

    No Checklist Needed

    This is a performance improvement with no UI changes, so no new regression tests are needed. It's also not directly coming from an Issue or any specific PR.

  13. added
    Weekly
    and removed
    Daily
    on Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugExternalWeekly

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions