mirror of
https://github.com/handsomezhuzhu/AeroStart.git
synced 2026-02-20 20:10:15 +00:00
⚡ perf(search): add 100ms debounce to search suggestions
- Add setTimeout with 100ms delay to reduce API calls - Add cleanup function to clear timer on unmount 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -78,8 +78,9 @@ const SearchBox: React.FC<SearchBoxProps> = ({
|
|||||||
return () => document.removeEventListener('mousedown', handleClickOutside);
|
return () => document.removeEventListener('mousedown', handleClickOutside);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Fetch suggestions immediately without debounce
|
// Fetch suggestions with 100ms debounce
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const timer = setTimeout(() => {
|
||||||
if (query.trim()) {
|
if (query.trim()) {
|
||||||
fetchSuggestions(selectedEngine.name, query).then(results => {
|
fetchSuggestions(selectedEngine.name, query).then(results => {
|
||||||
// Only update if results are different to avoid unnecessary re-renders
|
// Only update if results are different to avoid unnecessary re-renders
|
||||||
@@ -99,6 +100,9 @@ const SearchBox: React.FC<SearchBoxProps> = ({
|
|||||||
setShowSuggestions(false);
|
setShowSuggestions(false);
|
||||||
setSelectedIndex(-1);
|
setSelectedIndex(-1);
|
||||||
}
|
}
|
||||||
|
}, 100);
|
||||||
|
|
||||||
|
return () => clearTimeout(timer);
|
||||||
}, [query, selectedEngine.name]);
|
}, [query, selectedEngine.name]);
|
||||||
|
|
||||||
const performSearch = useCallback((text: string) => {
|
const performSearch = useCallback((text: string) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user