Stabilize useTodoCounts result reference - #97109
Draft
LukasMod wants to merge 1 commit into
Draft
Conversation
Contributor
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
Return the previously stored result object when no count or single-report ID changed, so consumers (e.g. SearchTypeMenuWide sections) keep a stable reference and memoized children do not re-render on unrelated Onyx writes to the subscribed collections. Adds a regression test for the stable and changed-reference behavior.
LukasMod
force-pushed
the
perf/useTodoCounts-stabilize
branch
from
July 27, 2026 15:08
cb74741 to
5c507fc
Compare
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Return the previously stored result object when no count or single-report ID changed, so consumers (e.g. SearchTypeMenuWide sections) keep a stable reference and memoized children do not re-render on unrelated Onyx writes to the subscribed collections. Adds a regression test for the stable and changed-reference behavior.
Explanation of Change
useTodoCountscomputes live to-do counts (Submit / Approve / Pay / Export) and, for buckets with exactly one report, that report's ID. It subscribes to several large Onyx collections (REPORT,POLICY,TRANSACTION,REPORT_ACTIONS,REPORT_METADATA, etc.), so it re-runs on every write to any of those collections — including writes that don't affect any to-do bucket (e.g. renaming a chat, receiving a message).Before this change, every such re-run built and returned a new
{counts, singleReportIDs}object, even when all values were identical. Consumers that use the result (or objects derived from it) as a dependency — most notably the memoized menu sections inSearchTypeMenuWide— saw a new reference each time and re-rendered on unrelated Onyx traffic.The change
src/hooks/useTodoCounts.tsalready stored the last computed result in state (frozen) to support theenabled: falsefreeze path, and already compared the fresh result against it to decide whether to re-store it. The fix is a single behavioral addition on the "nothing changed" branch:value, compare withfrozen, skip thesetFrozencall, but stillreturn value(a new object every render).return frozen— the exact same object reference as the previous render.When something did change, behavior is untouched: the fresh object is stored and returned, so consumers get a new reference and re-render as expected.
Why it's safe
enabled: falsefreeze path is unchanged.Tests
tests/unit/useTodoCountsTest.tsxgains a regression test asserting both directions:Fixed Issues
$
PROPOSAL:
Tests
Offline tests
QA Steps
Test 1 — Counts display correctly (baseline)
Expected: counts identical across all three surfaces and match reality.
Test 2 — Counts update live when a report changes state
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectioncanBeMissingparam foruseOnyxtoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari