diff --git a/app/composables/npm/useSearch.ts b/app/composables/npm/useSearch.ts index 780800b60f..14befae275 100644 --- a/app/composables/npm/useSearch.ts +++ b/app/composables/npm/useSearch.ts @@ -261,6 +261,8 @@ export function useSearch( const doSearch = provider === 'algolia' ? searchAlgolia : searchNpm const response = await doSearch(q, { size, from }) + const beforeCount = cache.value?.objects.length ?? 0 + if (cache.value && cache.value.query === q && cache.value.provider === provider) { const existingNames = new Set(cache.value.objects.map(obj => obj.package.name)) const newObjects = response.objects.filter(obj => !existingNames.has(obj.package.name)) @@ -279,6 +281,12 @@ export function useSearch( } } + // Bail if the provider gave us no new unique items + // Without something like this the recursion below never terminates. + if ((cache.value?.objects.length ?? 0) === beforeCount) { + return + } + if ( cache.value && cache.value.objects.length < targetSize &&