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(() => {
|
useEffect(() => {
|
||||||
|
const abortController = new AbortController();
|
||||||
|
|
||||||
if (searchString.length === 0) setResults([]);
|
if (searchString.length === 0) setResults([]);
|
||||||
else {
|
else {
|
||||||
let newResults = servicesAndBookmarks.filter((r) => {
|
let newResults = servicesAndBookmarks.filter((r) => {
|
||||||
@ -117,7 +119,10 @@ export default function QuickLaunch({
|
|||||||
|
|
||||||
if (!hideSearchSuggestions && searchProvider.suggestionUrl) {
|
if (!hideSearchSuggestions && searchProvider.suggestionUrl) {
|
||||||
if (searchString.trim() !== searchSuggestions[0]) {
|
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) => {
|
.then(async (searchSuggestionResult) => {
|
||||||
const newSearchSuggestions = await searchSuggestionResult.json();
|
const newSearchSuggestions = await searchSuggestionResult.json();
|
||||||
|
|
||||||
@ -164,6 +169,10 @@ export default function QuickLaunch({
|
|||||||
setCurrentItemIndex(0);
|
setCurrentItemIndex(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
abortController.abort();
|
||||||
|
};
|
||||||
}, [
|
}, [
|
||||||
searchString,
|
searchString,
|
||||||
servicesAndBookmarks,
|
servicesAndBookmarks,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user