Skip to content

perf: add useDebounce hook and apply to marketplace search#357

Merged
calvadev merged 4 commits intoshopstr-eng:mainfrom
nayan9617:fix/useDebounce-hook-tests
Apr 7, 2026
Merged

perf: add useDebounce hook and apply to marketplace search#357
calvadev merged 4 commits intoshopstr-eng:mainfrom
nayan9617:fix/useDebounce-hook-tests

Conversation

@nayan9617
Copy link
Copy Markdown
Contributor

@nayan9617 nayan9617 commented Apr 6, 2026

This PR adds a reusable useDebounce hook and integrates it into the marketplace search to reduce per-keystroke filtering overhead.

What changed:

  • New file: utils/hooks/useDebounce.ts - Generic debounce hook with proper cleanup
  • New file: utils/hooks/__tests__/useDebounce.test.ts- Unit tests covering:
  • Returns initial value immediately
  • Does not update before delay
  • Updates after configured delay
  • Cancels previous timer on rapid consecutive updates
  • Works with generic types (number case)
  • Modified: components/home/marketplace.tsx - Applied 300ms debounce to selectedSearch

Impact:

  • Marketplace search now debounces at 300ms, reducing filtering operations while typing
  • Hook is reusable across the codebase
  • All existing tests pass

Related:

Validation:

  • npm test -- utils/hooks/tests/useDebounce.test.ts
  • npm run type-check

…arch

Typing felt fine, but we were recalculating product matches on every single keypress.\n\nThis adds a tiny debounce hook and routes marketplace filtering through a 300ms debounced query so we only run filtering once the user pauses. It keeps input UX the same, but avoids unnecessary work now and prevents noisy relay calls later when search is wired remotely.
Added a focused test suite for useDebounce with fake timers:\n- immediate initial value\n- no early update before delay\n- update exactly after delay\n- rapid update cancellation behavior\n- generic type support with number values\n\nThis keeps the debounce behavior documented and protects it from regressions in future search changes.
Copilot AI review requested due to automatic review settings April 6, 2026 12:51
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 6, 2026

@nayan9617 is attempting to deploy a commit to the shopstr-eng Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds unit test coverage for a useDebounce hook and wires the hook into marketplace search to debounce filtering.

Changes:

  • Added useDebounce hook implementation (utils/hooks/useDebounce.ts)
  • Added Jest hook tests covering timing + cancellation semantics (utils/hooks/__tests__/useDebounce.test.ts)
  • Switched marketplace search prop to use a debounced value (components/home/marketplace.tsx)

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
utils/hooks/useDebounce.ts Introduces the debouncing hook used by UI code.
utils/hooks/tests/useDebounce.test.ts Adds timer-based unit tests to lock in debounce behavior.
components/home/marketplace.tsx Applies the debounce hook to marketplace search input before filtering.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@GautamBytes GautamBytes changed the title test: add useDebounce hook coverage (extension of #346) perf: add useDebounce hook and apply to marketplace search Apr 7, 2026
@GautamBytes
Copy link
Copy Markdown
Contributor

LGTM!!

@calvadev calvadev merged commit fb5078a into shopstr-eng:main Apr 7, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants