fix(swaps): fix stale search results after network filter change cp-13.39.0 - #44194
Conversation
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
✨ Files requiring CODEOWNER review ✨🔄 @MetaMask/swaps-engineers (2 files, +79 -1)
|
Builds ready [89acab3]
⚡ Performance Benchmarks (Total: 🟢 16 pass · 🟡 9 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
|
Builds ready [176bc86]
⚡ Performance Benchmarks (Total: 🟢 17 pass · 🟡 8 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
🧪 Validation RunVerdict: ✅ the regression test has power over the dependency fix — Claim: search refetches when the network filter changes, because Note Trial run of the MetaMask evidence skills — The fix is one entry in a dependency array at Falsification probe —
|
| Arm | Mutation | Result |
|---|---|---|
| A — baseline | none | Test Suites: 1 passed, 1 total Tests: 3 passed, 3 total |
| B — mutant | ui/hooks/bridge/useTokenSearchResults.ts:154 replaced |
Test Suites: 1 failed, 1 total Tests: 1 failed, 2 passed, 3 total |
The suite fails when the mechanism is removed and passes when restored, running the same 3 tests in both arms. The test has power.
Failing under mutation:
- ● useTokenSearchResults › refetches search results when chainIds change with the same search query
Produced by falsify-probe.sh at 767bc86afeb22d8b6b9f9a9bc92b3f509c3bd76b · node v24.13.1 · yarn.lock 5a67f92c7ce42ac0 · 0 tracked changes. Run: https://github.com/MajorLift/metamask-skills/actions/runs/30751002114 — logs and artifacts attached there.
Follows from the arm above
- Dropping
chainIdsfails 1 of 3 tests — the regression test added by this change is the one that fails. - The other 2 keep passing and all 3 run in both arms, so the module still loads; the failure is an assertion, not a broken import.
Open for review: the hook aborts in three places — abort('Asset balances changed'), abort('Search query changed'), and one on unmount. This arm covers the dependency array, not the staleness guarantee those aborts provide; whether a superseded response can still overwrite newer state is a separate question and a separate mutation.



Description
When changing the network filter in the bridge asset picker with an active search query, token search stopped refetching after several network switches. The list stayed mounted (network management UX from #43453), but
useTokenSearchResultsonly re-ran its fetch effect when searchQuery, stableMinimalAssetsString, or jwt changed - not when chainIds changed.Once
stableMinimalAssetsStringstopped changing (e.g. no owned tokens matching the query on the selected networks), further network changes did not trigger new/getTokens/searchrequests, leaving stale results.This PR adds
chainIdsto the refetch effect dependencies so search runs again whenever the network filter changes, without remounting the asset list or re-fetching popular/local tokens. A regression test covers the case wherechainIdschanges butstableMinimalAssetsStringdoes not.Changelog
CHANGELOG entry: Fixed bridge asset picker search not updating after changing the network filter while a search query is active.
Related issues
Fixes: #44145
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Low Risk
Small React hook dependency fix in bridge UI search with targeted unit test coverage; no auth, payments, or persistence changes.
Overview
Fixes stale bridge asset picker search results when users change the network filter while a search query is still active.
useTokenSearchResultsnow includeschainIdsin the effect that resets state and triggers the debounced/getTokens/searchfetch. Previously that effect only depended onsearchQuery,stableMinimalAssetsString, andjwt, so after several network switches—especially when owned assets no longer matched the query andstableMinimalAssetsStringstopped changing—no new search ran and the list could show outdated tokens.A unit test asserts that rerendering with a new
chainIdsset (same query, emptyassetsToInclude) callsfetchTokensBySearchQueryagain with the updated chains.Reviewed by Cursor Bugbot for commit 176bc86. Bugbot is set up for automated code reviews on this repo. Configure here.