Skip to content

Commit de26d13

Browse files
authored
fix(ui): bail on fetchMore recursion when no new items (#2606)
1 parent 189a568 commit de26d13

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

app/composables/npm/useSearch.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ export function useSearch(
261261
const doSearch = provider === 'algolia' ? searchAlgolia : searchNpm
262262
const response = await doSearch(q, { size, from })
263263

264+
const beforeCount = cache.value?.objects.length ?? 0
265+
264266
if (cache.value && cache.value.query === q && cache.value.provider === provider) {
265267
const existingNames = new Set(cache.value.objects.map(obj => obj.package.name))
266268
const newObjects = response.objects.filter(obj => !existingNames.has(obj.package.name))
@@ -279,6 +281,12 @@ export function useSearch(
279281
}
280282
}
281283

284+
// Bail if the provider gave us no new unique items
285+
// Without something like this the recursion below never terminates.
286+
if ((cache.value?.objects.length ?? 0) === beforeCount) {
287+
return
288+
}
289+
282290
if (
283291
cache.value &&
284292
cache.value.objects.length < targetSize &&

0 commit comments

Comments
 (0)