Problem
While working on Send a Message performance, @LukasMod noticed extra rerenders on the Spend tab, specifically in the SearchTypeMenuWide sections.
The root cause is in useTodoCounts. It subscribes to several large Onyx collections (REPORT, POLICY, TRANSACTION, REPORT_ACTIONS, REPORT_METADATA), so it re-runs on every write to any of them, even writes that don't change any to-do count (like renaming a chat or receiving a message). On each re-run it returned a new {counts, singleReportIDs} object, so memoized consumers like SearchTypeMenuWide saw a new reference and re-rendered on unrelated Onyx traffic.
Fix
PR: #97109
When no count and no single-report ID changed, return the previously stored object (frozen) so the reference stays stable and memoized children skip the rerender. When something does change, behavior is unchanged. Includes a regression test for both the stable and changed-reference cases.
Files:
src/hooks/useTodoCounts.ts
tests/unit/useTodoCountsTest.tsx
Related
Parent metric: #77176 ([Metrics] Improve ManualSendMessage)
Issue Owner
Current Issue Owner: @LukasMod
Problem
While working on Send a Message performance, @LukasMod noticed extra rerenders on the Spend tab, specifically in the
SearchTypeMenuWidesections.The root cause is in
useTodoCounts. It subscribes to several large Onyx collections (REPORT,POLICY,TRANSACTION,REPORT_ACTIONS,REPORT_METADATA), so it re-runs on every write to any of them, even writes that don't change any to-do count (like renaming a chat or receiving a message). On each re-run it returned a new{counts, singleReportIDs}object, so memoized consumers likeSearchTypeMenuWidesaw a new reference and re-rendered on unrelated Onyx traffic.Fix
PR: #97109
When no count and no single-report ID changed, return the previously stored object (
frozen) so the reference stays stable and memoized children skip the rerender. When something does change, behavior is unchanged. Includes a regression test for both the stable and changed-reference cases.Files:
src/hooks/useTodoCounts.tstests/unit/useTodoCountsTest.tsxRelated
Parent metric: #77176 ([Metrics] Improve ManualSendMessage)
Issue Owner
Current Issue Owner: @LukasMod