refactor: remove todos derived value - #94677
Conversation
ce8eb96 to
e681dbb
Compare
Codecov Report❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.
|
9825299 to
9aa3af6
Compare
|
@ZhenjaHorbach Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
This comment has been minimized.
This comment has been minimized.
Reviewer Checklist
Screenshots/VideosAndroid: HybridApp2026-06-29.14.23.55.movAndroid: mWeb Chrome2026-06-29.14.18.53.moviOS: HybridApp2026-06-29.14.23.55.moviOS: mWeb Safari2026-06-29.14.18.53.movMacOS: Chrome / Safari2026-06-29.14.10.44.mov |
72ed329 to
9c9c1ba
Compare
|
@codex review |
|
@MelvinBot Review |
ReviewVerdict: Solid, well-reasoned change. The core idea — replacing the always-on Worth confirming1. 2. Other notes (non-blocking)
This is an automated review from MelvinBot — treat it as a second pair of eyes, not a substitute for human review. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d795a8990b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/mountiny in version: 9.4.25-0 🚀
|
|
🚀 Deployed to production by https://github.com/cristipaval in version: 9.4.25-2 🚀
Bundle Size Analysis (Sentry): |
Explanation of Change
Performance optimization that scopes the to-do computation to the places that actually need it.
The problem: the
TODOSderived value runs outside the React lifecycle. Because it's a derived value, it recomputes on any dependency change (reports, transactions, report actions, policies, etc.) regardless of whether anything currently needs the result. That means the expensive to-do classification (createTodosReportsAndTransactions) runs constantly in the background — even when no screen is displaying the counts.The fix: move the computation into the React lifecycle via the
useTodoCountshook, so it only runs while a consumer is actually mounted, and then further scope it to consumers that are actually focused:enabled = trueparameter to theuseTodoCountshook (src/hooks/useTodoCounts.ts). Whenenabledisfalse, the hook freezes: it skips the expensive classification and returns the last captured result. The cache usesuseState+ a content-signature-guardedsetStateduring render (the repo's React-Compiler-safe freeze pattern, same asuseFrozenPreSelection) — no refs, so it passes the React Compiler compliance check.src/pages/Search/SearchTypeMenuNarrow.tsx: now callsuseTodoCounts(useIsFocused()), so to-do counts stop recomputing on background Onyx writes while the Search screen is unfocused, and recompute once on refocus (only if the underlying Onyx data actually changed — otherwise React Compiler memoization yields a cache hit).src/pages/home/ForYouSection/index.tsx: same treatment —useTodoCounts(useIsFocused())so the home "For You" section freezes its to-do classification when Home is unfocused.SearchTypeMenuWide(rendered as the search sidebar'sExtraContent) was intentionally left unchanged, becauseuseIsFocused()likely doesn't toggle in that navigator-chrome slot andreact-freezealready covers the away-from-Search case.Fixed Issues
$ #94686
PROPOSAL: N/A
Tests
Setup: Use an account with expense reports across all to-do buckets — at least one report each that you can submit, approve, pay, and export (export requires a workspace with a connected accounting integration where you're the exporter). Have several reports in some buckets and exactly one in another so single-report behavior can be verified.
Offline tests
N/A
QA Steps
Same as Tests
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand 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
Simulator.Screen.Recording.-.iPhone.17.Pro.-.2026-06-29.at.12.01.05.mov
iOS: mWeb Safari
MacOS: Chrome / Safari
Screen.Recording.2026-06-29.at.12.09.14.mov