Use AbortController to abort pending requests when search changes.
This commit is contained in:
parent
649ca33cd6
commit
53e740578c
@ -92,6 +92,8 @@ export default function QuickLaunch({
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const abortController = new AbortController();
|
||||
|
||||
if (searchString.length === 0) setResults([]);
|
||||
else {
|
||||
let newResults = servicesAndBookmarks.filter((r) => {
|
||||
@ -117,7 +119,10 @@ export default function QuickLaunch({
|
||||
|
||||
if (!hideSearchSuggestions && searchProvider.suggestionUrl) {
|
||||
if (searchString.trim() !== searchSuggestions[0]) {
|
||||
fetch(`/api/searchSuggestion?query=${encodeURIComponent(searchString)}&providerName=${searchProvider.name}`)
|
||||
fetch(
|
||||
`/api/searchSuggestion?query=${encodeURIComponent(searchString)}&providerName=${searchProvider.name}`,
|
||||
{ signal: abortController.signal },
|
||||
)
|
||||
.then(async (searchSuggestionResult) => {
|
||||
const newSearchSuggestions = await searchSuggestionResult.json();
|
||||
|
||||
@ -164,6 +169,10 @@ export default function QuickLaunch({
|
||||
setCurrentItemIndex(0);
|
||||
}
|
||||
}
|
||||
|
||||
return () => {
|
||||
abortController.abort();
|
||||
};
|
||||
}, [
|
||||
searchString,
|
||||
servicesAndBookmarks,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user