Commit d80a018
chore(runway): cherry-pick fix(predict): cp-7.62.0 debounce search input in PredictSearchOverlay (#24825)
- fix(predict): cp-7.62.0 debounce search input in PredictSearchOverlay
(#24820)
## **Description**
The PredictSearchOverlay component was triggering API requests for every
character typed in the search input. This caused excessive network
requests and poor UX.
**Solution:** Added a 200ms debounce to the search query using the
existing `useDebouncedValue` hook, which is already used throughout the
codebase for similar search functionality (Bridge, Card onboarding,
Trending tokens, etc.).
**Changes:**
- Import and use `useDebouncedValue` hook in PredictSearchOverlay
- Pass debounced query to `usePredictMarketData` instead of raw search
query
- Track debouncing state to show loading indicator during debounce
period
- Combined `isDebouncing` and `isFetching` states for seamless loading
UX
## **Changelog**
CHANGELOG entry: Fixed search input triggering excessive API calls in
Predictions
## **Related issues**
Fixes: https://consensyssoftware.atlassian.net/browse/PRED-486
## **Manual testing steps**
```gherkin
Feature: Debounced search in Predictions
Scenario: user types in search field
Given user has opened the Predictions feed
And user has tapped the search button
When user types "bitcoin" quickly
Then only one API request is made after typing stops
And skeleton loaders appear while debouncing
And search results appear after debounce completes
```
## **Screenshots/Recordings**
### **Before**
API call triggered on every keystroke (network tab shows multiple
requests)
### **After**
Single API call after 200ms debounce delay
https://github.com/user-attachments/assets/399cf46f-6979-4be5-8993-6d71cbf049ee
## **Pre-merge author checklist**
- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I've included tests if applicable
- [x] I've documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I've applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **Pre-merge reviewer checklist**
- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Improves Predictions search UX and reduces API calls by debouncing
input.
>
> - Import and use `useDebouncedValue` in `PredictSearchOverlay`;
introduce `SEARCH_DEBOUNCE_MS = 200`
> - Pass `debouncedSearchQuery` to `usePredictMarketData` instead of raw
`searchQuery`
> - Add `isDebouncing` and combine with `isFetching` as
`isSearchLoading` to show skeletons during debounce
> - Extend `PredictFeed.test.tsx` to mock `useDebouncedValue` and
assert: debounced query usage, loaders during debounce, results after
debounce, and `useDebouncedValue` called with `200`ms
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
2d6d25c. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
[9d02315](9d02315)
Co-authored-by: Luis Taniça <matallui@gmail.com>1 parent 9d5193b commit d80a018
2 files changed
Lines changed: 91 additions & 2 deletions
Lines changed: 79 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
46 | 54 | | |
47 | 55 | | |
48 | 56 | | |
| |||
232 | 240 | | |
233 | 241 | | |
234 | 242 | | |
| 243 | + | |
235 | 244 | | |
236 | 245 | | |
237 | 246 | | |
| |||
601 | 610 | | |
602 | 611 | | |
603 | 612 | | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
604 | 683 | | |
Lines changed: 12 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
| |||
515 | 516 | | |
516 | 517 | | |
517 | 518 | | |
| 519 | + | |
| 520 | + | |
518 | 521 | | |
519 | 522 | | |
520 | 523 | | |
| |||
523 | 526 | | |
524 | 527 | | |
525 | 528 | | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
526 | 534 | | |
527 | 535 | | |
528 | 536 | | |
529 | | - | |
| 537 | + | |
530 | 538 | | |
531 | 539 | | |
532 | 540 | | |
| 541 | + | |
| 542 | + | |
533 | 543 | | |
534 | 544 | | |
535 | 545 | | |
| |||
607 | 617 | | |
608 | 618 | | |
609 | 619 | | |
610 | | - | |
| 620 | + | |
611 | 621 | | |
612 | 622 | | |
613 | 623 | | |
| |||
0 commit comments