Skip to content

feat(performance): implement useDebounce hook to prevent global search API flooding (Resolves #662)#679

Merged
Aditya948351 merged 1 commit into
devpathindcommunity-india:masterfrom
abhinavkdeval08-design:feature/debounce-hook-662
Jun 21, 2026
Merged

feat(performance): implement useDebounce hook to prevent global search API flooding (Resolves #662)#679
Aditya948351 merged 1 commit into
devpathindcommunity-india:masterfrom
abhinavkdeval08-design:feature/debounce-hook-662

Conversation

@abhinavkdeval08-design

Copy link
Copy Markdown
Contributor

Description

This PR resolves the critical performance issue where the Global Search component (SearchModal.tsx) was triggering extensive useMemo filtering and potential state updates on every single keystroke.

By introducing a custom useDebounce hook, we throttle these heavy computations, ensuring they only execute after a brief pause in typing, significantly improving rendering performance on lower-end devices.

Related Issues

Changes Implemented

  1. Custom Hook (src/hooks/useDebounce.ts):
    • Created a strongly-typed, generic React hook to handle delay logic with proper useEffect cleanup timeouts to prevent memory leaks.
  2. Search Optimization (src/components/layout/SearchModal.tsx):
    • Integrated useDebounce with a 300ms threshold.
    • Separated the raw query (which keeps the input box responsive) from the debouncedQuery (which dictates when wikiResults and pageResults execute).
    • Replaced all conditional rendering and filtering dependencies from query to debouncedQuery.

Technical Details

  • Preserved existing keyboard shortcut functionality (Ctrl+K and Escape).
  • Kept the UI responsive; the input state updates instantly while the heavy lifting is deferred.

Checklist

  • Code follows project standards.
  • useDebounce utility created.
  • Search input handlers wrapped with debounce logic.
  • Tested locally for smooth performance without stuttering.

@Aditya948351 The search bar is now production-optimized and will no longer flood the event loop on every keystroke. Please review! 🚀

@github-actions github-actions Bot added gssoc26 This is a official GirlScript Summer of Code label. level:advanced Advanced issues type:feature type:performance labels Jun 20, 2026

@Aditya948351 Aditya948351 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is a great speed upgrade Adding the delay will save our database from crashing Really smart code.
As this was really an important fix, I will assign you a quality:clean labe looking towards your changes.

@Aditya948351 Aditya948351 added the gssoc:approved give 50+ base points label Jun 21, 2026
@Aditya948351 Aditya948351 merged commit 94f8201 into devpathindcommunity-india:master Jun 21, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved give 50+ base points gssoc26 This is a official GirlScript Summer of Code label. level:advanced Advanced issues quality:clean type:feature type:performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Architecture]: Implement Custom Debounce Hook for Search Inputs to Prevent API Rate-Limiting

2 participants