Repository navigation
Conversation
Applying a filter fired three identical Search calls for one query: the page-level fetch while the skeleton was up, the Search mount fetch once that response landed, and the save-recent-search upgrade queued behind the second. The in-flight check could not collapse them because the skeleton keeps Search unmounted until the page's request has already finished. The page now marks a one-shot token when it requests a first page, and the mount effect reads it instead of repeating the request. The token carries the totals intent, so a mount that needs totals the page did not request still fires.
|
@marufsharifi 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] |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / Safarifadsf.mov |
|
@elirangoshen, could you please confirm this: When the PR: pr.movMain: main.mov |
I will look into it and update you |
On a cached query Search is already on screen, so the page's flagged request left a token nothing read, and it skipped the refresh on the next return to the same query.
please try again |
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
If the user leaves before the response lands, Search mounts only on their return, and the page's token made it skip the refresh. Clear the token when the page loses focus so the return refreshes as on main.
|
@elirangoshen, could you please merge the main. thanks. |
…e-search-mount-fetch
done |
|
Thanks, i am still testing. |
marufsharifi
left a comment
There was a problem hiding this comment.
Looks good, just a few minor suggestions.
| } | ||
|
|
||
| // The page already fetched this first page, and that request finished before Search mounts, so search() no longer sees it. | ||
| if (!shouldRefreshOnReconnect && searchRequestOffset === 0 && isDataLoaded && consumePageRequestedSearch(queryJSON.hash, shouldCalculateTotals)) { |
There was a problem hiding this comment.
1. No test for the !shouldRefreshOnReconnect guard
No test has a page token set while the app comes back online. If this guard were dropped, a reconnect refresh could be silently skipped, and every current test would still pass.
2. No test for the searchRequestOffset === 0 guard while a token is set
loads the next page after a request that was in flight… covers paging, but only with no token set. Nothing checks that a first-page token (a) doesn't block a later-page request and (b) isn't used up by one.
There was a problem hiding this comment.
Hi, I Addressed by adding tests
The claim's guards were invisible to the suite: deleting any of them left every test green, which is what review pointed out. Two mocks were hiding the hook side. One replaced useFocusEffect with a bare jest.fn() so the callback never ran; the other ran the callback but dropped the cleanup it returned, so the blur path never executed. The token functions were stubbed and never asserted. The mock now keeps the cleanup, and the stubs are spies. Three hook tests: the page claims the first page when it owns the request, does not claim it when data is already on screen, and drops the claim on blur. The middle one needs cached data with a request still in flight — with data simply loaded the effect returns earlier and never reaches the guard, so a first version of that test passed with the guard deleted. Three component tests seed the claim directly, since only `search` is mocked and the real token functions share module state with the component. Removing `!shouldRefreshOnReconnect` or `searchRequestOffset === 0` now fails one each. The third covers the case review asked about: a mount with no claim does not re-request a first page that just finished loading. It pins that behaviour rather than the dependency itself.
Drops the parts the code already says and keeps the two that explain something non-obvious: why the fixture needs a request still in flight, and why a later page does not consume the claim.
…e-search-mount-fetch # Conflicts: # src/components/Search/index.tsx # src/hooks/useSearchPageSetup.ts
|
🚧 JS00001 has triggered a test Expensify/App build. You can view the workflow run here. |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/JS00001 in version: 9.4.94-0 🚀
|
|
No help site changes are needed for this PR, so I did not create a docs PR. This PR only removes duplicate Files reviewed
|
|
🚀 Deployed to production by https://github.com/Julesssss in version: 9.4.94-0 🚀
Bundle Size Analysis (Sentry): |
Explanation of Change
Problem: one filter apply on Spend sends three identical
Searchcommands. Samehash, sameoffset: 0, measured on a dev build:Two places fetch the same query, and they never overlap, so the duplicate check inside
search()never catches them:useSearchPageSetup.ts:99fetches when theqparam changes.Search/index.tsx:477fetches again when the component mounts.While the first request runs,
Searchis not on screen.SearchPageWide.tsx:130-144showsSearchLoadingSkeletoninstead, andkey={queryJSON.hash}rebuilds the subtree on every query change, soSearchmounts only after the response arrives. By thensearch()has already removed the first request from its in-flight map, and nothing stops the second one.The third follows from the second. Once it is running,
isInitialSearchPendingturns true, so the early return atuseSearchPageSetup.ts:92-94no longer applies and the page fetches again with the flag set. That lands on a running request with no flag, soneedsSaveRecentSearchUpgradequeues one more.Fix: give the first page one owner.
useSearchPageSetupleaves a token when it fetches, and the mount reads that token once instead of fetching again. The token records whether totals were asked for, so a mount that needs totals the page did not request still fetches. Pagination, reconnect refresh, error retry and all-matching totals are unchanged, andneedsSaveRecentSearchUpgradestays as it is - that branch is what gets a user's own query to the backend with the flag.One token, not a set: a new query replaces the old one, so a token left over from a query the user moved away from cannot skip a later refresh of it.
Automated tests: new
tests/unit/Search/searchPageRequestedTokenTest.tswith 6 cases covering the token's lifetime, including the leftover-token and totals cases, plus atests/ui/SearchPageTest.tsxcase that asserts one first-page request per query change. That test was checked against the unfixed code and fails there (Expected: 1, Received: 2).Fixed Issues
$ #101642
PROPOSAL:
Tests
Searchcommand is sent for that query - onejsonQuerywith the newhashatoffset: 0, carryingshouldSaveRecentSearch: true.offset: 50.Offline tests
Searchis a READ command. Both call sites already return early when offline, and the new check only runs on a path that needs loaded data, so offline behavior is unchanged. Verified filtering while offline and on return to online.QA Steps
No user-facing behavior change - this removes redundant network calls. Regression checks only:
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, 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.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